Derives a key from a password using an OpenSSL-compatible version of the PBKDF1 algorithm.
based on the OpenSSL EVP_BytesToKey method for generating key and iv http://www.openssl.org/docs/crypto/EVP_BytesToKey.html
Inheritance: System.Security.Cryptography.DeriveBytes
Exemplo n.º 1
0
        /// <summary>
        /// Sets or resets the encryption level for the encryption instance
        /// </summary>
        /// <param name="keysize">The encryption level as an CryptoLevel enum</param>
        public void SetEncryptionLevel(CryptoLevel keysize = CryptoLevel.AES256)
        {
            // update the keySize property with the requested encryption level
            KeySize = keysize;

            // at this time we are utilizing hard-coded values
            ConfigureCryptoInCode();

            // convert the CryptoLevel to an integer to assist calculationg the crypto properties
            m_encryptionBits = KeySize == CryptoLevel.AES256 ? 256 : KeySize == CryptoLevel.AES128 ? 128 : 0;

            // initialize the IV array
            iv_array = new byte[16];

            // initialize the Key array
            key_array = new byte[m_encryptionBits / 8];

            // generate the Crypto Key and IV
            // create the key and Initial Vector from the
            OpenSslCompatDeriveBytes crap = new OpenSslCompatDeriveBytes(m_cryptoSalt, m_nonce, m_cryptoHash, m_cryptoIterations);

            stuff_array = crap.GetBytes((m_encryptionBits / 8) + 16);
            Buffer.BlockCopy(stuff_array, 0, key_array, 0, m_encryptionBits / 8);
            Buffer.BlockCopy(stuff_array, m_encryptionBits / 8, iv_array, 0, 16);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets or resets the encryption level for the encryption instance
        /// </summary>
        /// <param name="keysize">The encryption level as an CryptoLevel enum</param>
        public static void SetEncryptionLevel(CryptoLevel keysize = CryptoLevel.AES256)
        {
            // update the keySize property with the requested encryption level
            KeySize = keysize;

            // at this time we are utilizing hard-coded values
            ConfigureCryptoInCode();

            // convert the CryptoLevel to an integer to assist calculationg the crypto properties
            m_encryptionBits = KeySize == CryptoLevel.AES256 ? 256 : KeySize == CryptoLevel.AES128 ? 128 : 0;

            // initialize the IV array
            iv_array = new byte[16];

            // initialize the Key array
            key_array = new byte[m_encryptionBits / 8];

            // generate the Crypto Key and IV
            // create the key and Initial Vector from the
            OpenSslCompatDeriveBytes crap = new OpenSslCompatDeriveBytes(m_cryptoSalt, m_nonce, m_cryptoHash, m_cryptoIterations);

            stuff_array = crap.GetBytes((m_encryptionBits / 8) + 16);
            Buffer.BlockCopy(stuff_array, 0, key_array, 0, m_encryptionBits / 8);
            Buffer.BlockCopy(stuff_array, m_encryptionBits / 8, iv_array, 0, 16);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets or resets the encryption level for the encryption instance
        /// </summary>
        /// <param name="keysize">The encryption level as an CryptoLevel enum</param>
        public void InitializeEncryption(CryptoLevel aesize = CryptoLevel.AES256, String hash = "SHA1", Int16 iterations = 5, Int16 nonceLength = 8, String salt = "", String nonce = "")
        {
            KeySize = aesize;
            m_cryptoHash = hash;
            m_cryptoIterations = iterations;
            NonceLength = nonceLength;

            // if a salt and a nonce have been provided use them:
            if (!String.IsNullOrWhiteSpace(salt) && !String.IsNullOrWhiteSpace(nonce))
            {
                Nonce = Encoding.ASCII.GetBytes(nonce);
                CryptoSalt = salt;
            }
            //otherwise; use the calculated nonce and salt values

            // initialize the IV array
            iv_array = new byte[16];

            // initialize the Key array
            key_array = new byte[m_encryptionBits / 8];

            // generate the Crypto Key and IV
            // create the key and Initial Vector from the
            OpenSslCompatDeriveBytes crap = new OpenSslCompatDeriveBytes(CryptoSalt, Nonce, CryptoHash, CryptoIterations);

            stuff_array = crap.GetBytes((m_encryptionBits / 8) + 16);
            Buffer.BlockCopy(stuff_array, 0, key_array, 0, m_encryptionBits / 8);
            Buffer.BlockCopy(stuff_array, m_encryptionBits / 8, iv_array, 0, 16);
        }