Пример #1
0
        public OpenSslCryptoTransform(SymmetricAlgorithm algo, bool encrypt, byte[] rgbKey, byte[] rgbIV)
            : base(algo, encrypt, rgbKey, rgbIV)
        {
            OpenSslUtil.EnsureAvailability ();

            this.context = Native.EVP_CIPHER_CTX_new ();

            var cptr = this.GetCipher (algo.Mode, rgbKey.Length);
            var op = encrypt ? Native.CipherOperation.Encrypt : Native.CipherOperation.Decrypt;

            fixed (byte* pkey = &rgbKey[0])
                fixed (byte* piv = &iv[0]) {
                    Native.ExpectSuccess (Native.EVP_CipherInit_ex (this.context, cptr, IntPtr.Zero, (IntPtr)pkey, (IntPtr)piv, op));
                }

            Native.ExpectSuccess (Native.EVP_CIPHER_CTX_set_key_length (this.context, rgbKey.Length));
            Native.ExpectSuccess (Native.EVP_CIPHER_CTX_set_padding (this.context, 0));
        }
Пример #2
0
        public OpenSslCryptoTransform(SymmetricAlgorithm algo, bool encrypt, byte[] rgbKey, byte[] rgbIV)
            : base(algo, encrypt, rgbKey, rgbIV)
        {
            OpenSslUtil.EnsureAvailability();

            this.context = Native.EVP_CIPHER_CTX_new();

            var cptr = this.GetCipher(algo.Mode, rgbKey.Length);
            var op   = encrypt ? Native.CipherOperation.Encrypt : Native.CipherOperation.Decrypt;

            fixed(byte *pkey = &rgbKey[0])
            fixed(byte *piv = &iv[0])
            {
                Native.ExpectSuccess(Native.EVP_CipherInit_ex(this.context, cptr, IntPtr.Zero, (IntPtr)pkey, (IntPtr)piv, op));
            }

            Native.ExpectSuccess(Native.EVP_CIPHER_CTX_set_key_length(this.context, rgbKey.Length));
            Native.ExpectSuccess(Native.EVP_CIPHER_CTX_set_padding(this.context, 0));
        }