Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpbcgr.Client_Security_Exchange_Pdu.ToBytes C# (CSharp) Method

ToBytes() public method

Encode this structure into byte array.
public ToBytes ( ) : byte[]
return byte[]
        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);
        }