Exemple #1
0
        /// <summary>
        /// Decrypts a buffer.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <returns>The decrypted buffer.</returns>
        public byte[] Decrypt(byte[] buffer)
        {
            byte[] ret = new byte[buffer.Length];
            switch (_algorithm)
            {
            case BlowfishAlgorithm.ECB:
                Libeay32.CAST_ecb_encrypt(buffer, ret, _key, 0);
                break;

            case BlowfishAlgorithm.CBC:
                Libeay32.CAST_cbc_encrypt(buffer, ret, buffer.Length, _key, _decryptIv, 0);
                break;

            case BlowfishAlgorithm.CFB64:
                Libeay32.CAST_cfb64_encrypt(buffer, ret, buffer.Length, _key, _decryptIv, ref _decryptNum, 0);
                break;

            case BlowfishAlgorithm.OFB64:
                Libeay32.CAST_ofb64_encrypt(buffer, ret, buffer.Length, _key, _decryptIv, out _decryptNum);
                break;
            }
            return(ret);
        }
Exemple #2
0
 /// <summary>
 /// Sets the key for the cryptography.
 /// </summary>
 /// <param name="data">The key</param>
 public void SetKey(byte[] data)
 {
     _encryptNum = 0;
     _decryptNum = 0;
     Libeay32.CAST_set_key(_key, data.Length, data);
 }