示例#1
0
        /// <summary>
        ///   standard constructor
        /// </summary>
        /// <param name="sKey">
        ///   the string which is used as the key material, internally
        ///   a UTF8 representation is used, hashed with SHA-1, thus
        ///   we use a 160bit key (which does not make weak keys safe!)
        /// </param>
        public BlowfishSimple
            (String sKey)
        {
            m_ue = new UTF8Encoding();

            byte[] keyRaw = TransformKey(sKey);

            HashAlgorithm sha = new SHA1CryptoServiceProvider();

            byte[] key = sha.ComputeHash(keyRaw);
            sha = null;

            m_rng = new RNGCryptoServiceProvider();

            byte[] checksumSalt = new byte[20];
            m_rng.GetBytes(checksumSalt);

            byte[] checksum      = CalcKeyChecksum(checksumSalt, keyRaw);
            byte[] checksumCombo = new byte[checksumSalt.Length + checksum.Length];
            Array.Copy(checksumSalt, 0, checksumCombo, 0, checksumSalt.Length);
            Array.Copy(checksum, 0, checksumCombo, checksumSalt.Length, checksum.Length);

            m_sKeyChecksum = Convert.ToBase64String(checksumCombo);

            // (start with a dummy IV)
            byte[] iv = new byte[Blowfish.BLOCKSIZE];

            m_bfc = new BlowfishCBC(key, iv);

            Array.Clear(keyRaw, 0, keyRaw.Length);
            Array.Clear(key, 0, key.Length);
            Array.Clear(iv, 0, iv.Length);
        }
示例#2
0
        /// <summary>
        /// constructor
        /// </summary>
        public BlowfishAlgorithm() : base()
        {
            m_bf  = null;
            m_bfc = null;

            // FIXME: are we supposed to create a default key and IV?
            IVValue      = null;
            KeyValue     = null;
            KeySizeValue = Blowfish.MAXKEYLENGTH * 8;

            LegalBlockSizesValue    = new KeySizes[1];
            LegalBlockSizesValue[0] = new KeySizes(BlockSize, BlockSize, 8);

            LegalKeySizesValue    = new KeySizes[1];
            LegalKeySizesValue[0] = new KeySizes(0, Blowfish.MAXKEYLENGTH * 8, 8);

            ModeValue = CipherMode.ECB;

            m_rng = null;
        }
示例#3
0
        public BlowfishAlgorithm() : base()
        {
            m_bf  = null;
            m_bfc = null;


            IVValue      = null;
            KeyValue     = null;
            KeySizeValue = Blowfish.MAXKEYLENGTH * 8;

            LegalBlockSizesValue    = new KeySizes[1];
            LegalBlockSizesValue[0] = new KeySizes(BlockSize, BlockSize, 8);

            LegalKeySizesValue    = new KeySizes[1];
            LegalKeySizesValue[0] = new KeySizes(0, Blowfish.MAXKEYLENGTH * 8, 8);

            ModeValue = CipherMode.ECB;

            m_rng = null;
        }
示例#4
0
        BlowfishAlgorithm
        (
            byte[] key,
            byte[] iv,
            bool blCBC,
            bool blIsEncryptor
        )
        {
            if (null == key)
            {
                GenerateKey();
            }
            else
            {
                Key = key;
            }

            if (blCBC)
            {
                if (null == iv)
                {
                    GenerateIV();
                }
                else
                {
                    IV = iv;
                }

                m_bf  = null;
                m_bfc = new BlowfishCBC(KeyValue, IVValue);
            }
            else
            {
                m_bf  = new Blowfish(KeyValue);
                m_bfc = null;
            }

            m_blIsEncryptor = blIsEncryptor;
        }