public override byte[] ToBytes()
{
List<byte> randomBuffer = new List<byte>();
if (securityExchangePduData.clientRandom != null)
{
if (context.ServerExponent == null || context.ServerModulus == null)
{
throw new InvalidDataException(
"The public key of the certificate to encrypt client random number is invalid.");
}
byte[] encryptedClientRandom = RdpbcgrUtility.GenerateEncryptedRandom(securityExchangePduData.clientRandom,
context.ServerExponent,
context.ServerModulus);
securityExchangePduData.length = (uint)encryptedClientRandom.Length;
RdpbcgrEncoder.EncodeStructure(randomBuffer, securityExchangePduData.length);
RdpbcgrEncoder.EncodeBytes(randomBuffer, encryptedClientRandom);
context.ClientRandomNumber = securityExchangePduData.clientRandom;
context.GenerateSessionKey();
}
else
{
RdpbcgrEncoder.EncodeStructure(randomBuffer, 0);
}
List<byte> totalBuffer = new List<byte>();
RdpbcgrEncoder.EncodeSlowPathPdu(totalBuffer, commonHeader, randomBuffer.ToArray(), context);
return RdpbcgrUtility.ToBytes(totalBuffer);
}