internal BlowfishCryptography(BlowfishAlgorithm algorithm)
 {
     _algorithm = algorithm;
     _encryptIv = new byte[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
     _decryptIv = new byte[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
     bf_key_st key = new bf_key_st();
     key.P = new UInt32[16 + 2];
     key.S = new UInt32[4 * 256];
     _key = Marshal.AllocHGlobal(key.P.Length * sizeof(UInt32) + key.S.Length * sizeof(UInt32));
     Marshal.StructureToPtr(key, _key, false);
     _encryptNum = 0;
     _decryptNum = 0;
 }
示例#2
0
        public Blowfish(BlowfishAlgorithm algorithm)
        {
            _algorithm = algorithm;
            _encryptIv = new byte[8] {
                0, 0, 0, 0, 0, 0, 0, 0
            };
            _decryptIv = new byte[8] {
                0, 0, 0, 0, 0, 0, 0, 0
            };
            bf_key_st key = new bf_key_st();

            key.P = new UInt32[16 + 2];
            key.S = new UInt32[4 * 256];
            _key  = Marshal.AllocHGlobal(key.P.Length * sizeof(UInt32) + key.S.Length * sizeof(UInt32));
            Marshal.StructureToPtr(key, _key, false);
            _encryptNum = 0;
            _decryptNum = 0;
        }
        /// <summary>
        /// Blowfish is a keyed, symmetric block cipher, designed in 1993 by Bruce Schneier and included in a large
        /// number of cipher suites and encryption products. Blowfish provides a good encryption rate in software and no
        /// effective cryptanalysis of it has been found to date. However, the Advanced Encryption Standard now receives
        /// more attention. Schneier designed Blowfish as a general-purpose algorithm, intended as an alternative to the
        /// aging DES and free of the problems and constraints associated with other algorithms. Schneier has stated that,
        /// "Blowfish is unpatented, and will remain so in all countries. The algorithm is hereby placed in the public
        /// domain, and can be freely used by anyone." The implementation type in use is CFB64.
        /// </summary>
        public BlowfishCipher()
        {
            _encryptIv = new byte[8] {
                0, 0, 0, 0, 0, 0, 0, 0
            };
            _decryptIv = new byte[8] {
                0, 0, 0, 0, 0, 0, 0, 0
            };
            bf_key_st key = new bf_key_st();

            key.P = new UInt32[16 + 2];
            key.S = new UInt32[4 * 256];
            _key  = Marshal.AllocHGlobal(key.P.Length * sizeof(UInt32) + key.S.Length * sizeof(UInt32));
            Marshal.StructureToPtr(key, _key, false);
            _encryptNum = 0;
            _decryptNum = 0;
            KeySchedule(InitialKey);
        }