EncryptMessage() public method

public EncryptMessage ( ContentType contentType, NetMQMessage plainMessage ) : NetMQMessage
contentType ContentType This identifies the type of content: ChangeCipherSpec, Handshake, or ApplicationData.
plainMessage NetMQMessage The unencrypted form of the message to be encrypted.
return NetMQMessage
コード例 #1
0
        internal NetMQMessage InternalEncryptAndWrapMessage(ContentType contentType, NetMQMessage plainMessage)
        {
            NetMQMessage encryptedMessage = m_recordLayer.EncryptMessage(contentType, plainMessage);

            encryptedMessage.Push(new byte[] { (byte)contentType });
            encryptedMessage.Push(m_protocolVersion);

            return(encryptedMessage);
        }
コード例 #2
0
        }        /// <summary>

        /// 包装成RecordLayer
        /// </summary>
        /// <param name="contentType">This identifies the type of content: ChangeCipherSpec, Handshake, or ApplicationData.</param>
        /// <param name="plainMessage">The unencrypted form of the message to be encrypted.</param>
        /// <returns></returns>
        internal byte[] WrapToRecordLayerMessage(ContentType contentType, byte[] bytes)
        {
            //将数据加密
            //Change Cipher Spec 步骤之前返回明文
            byte[] encryptedBytes   = RecordLayer.EncryptMessage(contentType, bytes);
            byte[] recordLayerBytes = new byte[encryptedBytes.Length + 5];
            recordLayerBytes[0] = (byte)contentType;
            recordLayerBytes[1] = ProtocolVersion[0];
            recordLayerBytes[2] = ProtocolVersion[1];
            /// ContentType type;change_cipher_spec(20), alert(21), handshake(22), application_data(23), (255)
            /// ProtocolVersion version;33
            /// uint16 length;
            /// opaque fragment[TLSPlaintext.length];
            if (ProtocolVersion.SequenceEqual(Constants.V3_3))
            {
                //增加长度
                byte[] lengthBytes = encryptedBytes.LengthToBytes(2);
                Buffer.BlockCopy(lengthBytes, 0, recordLayerBytes, 3, lengthBytes.Length);
            }
            Buffer.BlockCopy(encryptedBytes, 0, recordLayerBytes, 5, encryptedBytes.Length);

            return(recordLayerBytes);
        }