public void Dispose() { if (this._handle != null) { _CIPHER.EVP_CIPHER_CTX_cleanup(this._handle); _CIPHER.EVP_CIPHER_CTX_free(this._handle); } this._handle = null; }
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(); }
public static extern int EVP_CIPHER_CTX_set_iv_length(EVP_CIPHER_CTX *handle, int length);
public static extern int EVP_CIPHER_CTX_block_size(EVP_CIPHER_CTX *handle);
public static extern int EVP_CIPHER_CTX_iv_length(EVP_CIPHER_CTX *handle);
public static extern void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *handle);
public static extern EVP_CIPHER *EVP_CIPHER_CTX_cipher(EVP_CIPHER_CTX *handle);
public static extern int EVP_CipherUpdate(EVP_CIPHER_CTX *handle, byte[] outbuf, ref int outlen, byte[] inbuf, int inlen);
public static extern int EVP_CipherUpdate(EVP_CIPHER_CTX *handle, IntPtr outbuf, ref int outlen, IntPtr inbuf, int inlen);
public static extern int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *handle, int type, int arg, byte[] ptr);
public static extern int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *handle, int type, int arg, IntPtr ptr);
public static extern int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *handle, int padding);
public static extern int EVP_CipherInit_ex(EVP_CIPHER_CTX *handle, EVP_CIPHER *cipher, IntPtr engine, byte[] key, byte[] iv, int enc);
public static extern void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *handle);
public static extern int EVP_CipherFinal_ex(EVP_CIPHER_CTX *handle, IntPtr outbuf, ref int outlen);
public SCIPHER(SType type, bool encrypt) { EVP_CIPHER *cipher = null; // Statically allocated (MT), don't free EVP_CIPHER_CTX *handle = null; try { cipher = (EVP_CIPHER*) _ciphers[type](); } 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._encrypt = encrypt; return ; Bailout: if (handle != null) _CIPHER.EVP_CIPHER_CTX_free(handle); throw new EVPException(); }
public static extern void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *handle);