<div class="content"><p>The R_KeyExchangePhase2 method receives the encrypted client
session and hash keys in response to the <a href="7acc4bbb-c20b-439a-b5f4-77e2acbf0949" data-linktype="relative-path">R_KeyExchangePhase1</a> method
and returns the encrypted server hash keys.</p><dl>
<dd>
<div><pre> HRESULT R_KeyExchangePhase2(
   [unique, in] IIS_CRYPTO_BLOB* pClientSessionKeyBlob,
   [unique, in] IIS_CRYPTO_BLOB* pClientHashBlob,
   [out] IIS_CRYPTO_BLOB** ppServerHashBlob
 );
</pre></div>
</dd></dl><p><b>pClientSessionKeyBlob: </b>A pointer to an <a href="bbe15a83-a32d-48a3-9564-8dacea965e83" data-linktype="relative-path">IIS_CRYPTO_BLOB</a> structure
containing the encrypted client <a href="1243ba70-74ca-44f9-be0b-dfd6697010b4#gt_4f67a585-fb00-4166-93e8-cf4abca8226d" data-linktype="relative-path">session key</a>.</p><p><b>pClientHashBlob: </b>A pointer to an
IIS_CRYPTO_BLOB structure containing the encrypted client hash key.</p><p><b>ppServerHashBlob: </b>A pointer to a set of
IIS_CRYPTO_BLOB structures containing the encrypted session hash keys.</p><p><b>Return Values: </b>A signed 32-bit value that
indicates return status. If the method returns a negative value, it failed. If
the 12-bit facility code (bits 16–27) is set to 0x007, the value contains a
Win32 error code in the lower 16 bits. Zero or positive values indicate
success, with the lower 16 bits in positive nonzero values containing warnings
or flags defined in the method implementation. For more information about Win32
error codes and <a href="../ms-dtyp/a9046ed2-bfb2-4d56-a719-2824afce59ac" data-linktype="relative-path">HRESULT</a>
values, see <a href="../ms-erref/1bc92ddf-b79e-413c-bbaa-99a5281a6c90" data-linktype="relative-path">[MS-ERREF]</a>.</p><dl>
<dd>
<table><thead>
  <tr>
   <th>
   <p>Return value/code</p>
   </th>
   <th>
   <p>Description</p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>
  <p>0x00000000</p>
  <p>S_OK</p>
  </td>
  <td>
  <p>The call was successful.</p>
  </td>
 </tr></tbody></table>
</dd></dl><p>The <a href="1243ba70-74ca-44f9-be0b-dfd6697010b4#gt_e127848e-c66d-427d-b3aa-9f904fa4ada7" data-linktype="relative-path">opnum</a>
field value for this method is 27. </p><p>When the server receives the R_KeyExchangePhase2 method, it
SHOULD check the state of the <a href="1243ba70-74ca-44f9-be0b-dfd6697010b4#gt_e58c72cc-2506-4e51-b33d-fbefe4bd6138" data-linktype="relative-path">secure
session</a>. If the session negotiation has not started yet by processing the
R_KeyExchangePhase1 method, the MD_ERROR_SECURE_CHANNEL_FAILURE error code MUST
be returned back to client. </p><p>If any of the parameters sent by the client are empty, the
server SHOULD return an E_INVALIDARG error code.</p><p>Upon successful validation, the server SHOULD perform the
following steps:</p><ol><li><p><span>    </span>Decrypt the
encrypted client&#39;s session key using the server&#39;s <a href="1243ba70-74ca-44f9-be0b-dfd6697010b4#gt_44291345-1fdd-4be9-ae71-a6bbe1f9406c" data-linktype="relative-path">key exchange private key</a>.</p>
</li><li><p><span>    </span>Store the
client&#39;s session key.</p>
</li><li><p><span>    </span>Compute the hash
of the following 3 values (in this order):</p>
<ol><li><p><span>   
</span>Client&#39;s session key.</p>
</li><li><p><span>   
</span>Server&#39;s session key.</p>
</li><li><p><span>   
</span>Value of HASH_TEXT_STRING_1, as specified in section <a href="b7acace4-3116-4d84-9cc7-c02c642fb234" data-linktype="relative-path">2.2.3</a>. </p>
</li></ol></li><li><p><span>    </span>Compare the hash
computed in the previous step with the hash received from the client. If they
match, the client has proved that it owns the client&#39;s key exchange private key
that matches the client&#39;s <a href="1243ba70-74ca-44f9-be0b-dfd6697010b4#gt_3ac30f9e-dfc0-4d06-a450-49ed662b4328" data-linktype="relative-path">key
exchange public key</a>. It proved it by being able to decrypt the server&#39;s
session key that was needed for the hash calculation.</p>
</li><li><p><span>    </span>Compute hash of
the following 2 values (in this order):</p>
<ol><li><p><span>   
</span>Client&#39;s session key.</p>
</li><li><p><span>   
</span>Value of HASH_TEXT_STRING_2, as specified in 2.2.3.</p>
</li></ol></li><li><p><span>    </span>Build an
IIS_CRYPTO_BLOB structure with the <b>BlobSignature</b> field set to
HASH_BLOB_SIGNATURE and store the hash calculated in the previous step.</p>
</li><li><p><span>    </span>Send the IIS_CRYPTO_BLOB
structure calculated in the previous step to the client.</p>
</li></ol></div>