示例#1
0
        public CIPHER(CType type, CMode mode, bool encrypt)
        {
            EVP_CIPHER *    cipher = null; // Statically allocated (MT), don't free
            EVP_CIPHER_CTX *handle = null;

            try {
                cipher = (EVP_CIPHER *)_ciphers[new Tuple <CType, CMode>(type, mode)]();
            } catch (KeyNotFoundException) {}

            if (cipher == null)
            {
                goto Bailout;
            }

            if ((handle = _CIPHER.EVP_CIPHER_CTX_new()) == null)
            {
                goto Bailout;
            }
            _CIPHER.EVP_CIPHER_CTX_init(handle);
            if (_CIPHER.EVP_CipherInit_ex(handle, cipher, IntPtr.Zero, null, null, encrypt ? 1 : 0) == 0)
            {
                goto Bailout;
            }
            _CIPHER.EVP_CIPHER_CTX_set_padding(handle, 0);

            this._handle  = handle;
            this._type    = type;
            this._mode    = mode;
            this._encrypt = encrypt;

            return;

Bailout:
            if (handle != null)
            {
                _CIPHER.EVP_CIPHER_CTX_free(handle);
            }
            throw new EVPException();
        }
示例#2
0
 public static extern int EVP_CipherInit_ex(EVP_CIPHER_CTX *handle, EVP_CIPHER *cipher, IntPtr engine, byte[] key, byte[] iv, int enc);