Opc.Ua.Bindings.TcpChannel.Encrypt C# (CSharp) Method

Encrypt() protected method

Encrypts the buffer using asymmetric encryption.
Start and count specify the block of data to be encrypted. The caller must ensure that count is a multiple of the input block size for the current cipher. The header specifies unencrypted data that must be copied to the output.
protected Encrypt ( ArraySegment dataToEncrypt, ArraySegment headerToCopy, X509Certificate2 receiverCertificate ) : ArraySegment
dataToEncrypt ArraySegment
headerToCopy ArraySegment
receiverCertificate System.Security.Cryptography.X509Certificates.X509Certificate2
return ArraySegment
        protected ArraySegment<byte> Encrypt(
            ArraySegment<byte> dataToEncrypt,
            ArraySegment<byte> headerToCopy,
            X509Certificate2   receiverCertificate)
        {      
            switch (SecurityPolicyUri)
            {
                default:
                case SecurityPolicies.None:
                {
                    byte[] encryptedBuffer = BufferManager.TakeBuffer(SendBufferSize, "Encrypt");

                    Array.Copy(headerToCopy.Array, headerToCopy.Offset, encryptedBuffer, 0, headerToCopy.Count);
                    Array.Copy(dataToEncrypt.Array, dataToEncrypt.Offset, encryptedBuffer, headerToCopy.Count, dataToEncrypt.Count);

                    return new ArraySegment<byte>(encryptedBuffer, 0, dataToEncrypt.Count+headerToCopy.Count);
                }
                case SecurityPolicies.Basic256:
                case SecurityPolicies.Basic256Sha256:
                {
                    return Rsa_Encrypt(dataToEncrypt, headerToCopy, receiverCertificate, true);
                }

                case SecurityPolicies.Basic128Rsa15:
                {
                    return Rsa_Encrypt(dataToEncrypt, headerToCopy, receiverCertificate, false);
                }
            }
        }

Same methods

TcpChannel::Encrypt ( TcpChannelToken token, ArraySegment dataToEncrypt, bool useClientKeys ) : void