コード例 #1
0
        /// <summary>To execute a selftest.</summary>
        /// <remarks>Call this method to make sure that the implemenation is able to produce
        /// valid output according to the specification. This should usually be done at process
        /// startup time, before the usage of this class and its inherited variants.</remarks>
        /// <returns>True if the selftest passed or false is it failed. In such a case you must
        /// not use the cipher to avoid data corruption!</returns>
        public static bool RunSelfTest()
        {
            uint hi = TEST_VECTOR_PLAIN[0];
            uint lo = TEST_VECTOR_PLAIN[1];

            BlowfishECB bfe = new BlowfishECB(TEST_KEY, 0, TEST_KEY.Length);

            bfe.EncryptBlock(hi, lo, out hi, out lo);

            if ((TEST_VECTOR_CIPHER[0] != hi) ||
                (TEST_VECTOR_CIPHER[1] != lo))
            {
                return(false);
            }

            bfe.DecryptBlock(hi, lo, out hi, out lo);

            if ((TEST_VECTOR_PLAIN[0] != hi) ||
                (TEST_VECTOR_PLAIN[1] != lo))
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        private BlowfishAlgorithm(byte[] key, byte[] iv, bool useCBC, bool isEncryptor)
        {
            if (null == key)
            {
                GenerateKey();
            }
            else
            {
                Key = key;
            }

            if (useCBC)
            {
                IV = this.origIV = iv;

                this.bfc = new BlowfishCBC(KeyValue, 0, KeyValue.Length);
                this.bfc.SetIV(IVValue, 0);
            }
            else
            {
                this.bfe = new BlowfishECB(KeyValue, 0, KeyValue.Length);
            }

            this.isEncryptor = isEncryptor;
        }
コード例 #3
0
        private BlowfishAlgorithm(byte[] key, byte[] iv, bool useCBC, bool isEncryptor)
        {
            if (null == key)
            {
                GenerateKey();
            }
            else
            {
                Key = key;
            }

            if (useCBC)
            {
                IV = this.origIV = iv;

                this.bfc = new BlowfishCBC(KeyValue, 0, KeyValue.Length);
                this.bfc.SetIV(IVValue, 0);
            }
            else
            {
                this.bfe = new BlowfishECB(KeyValue, 0, KeyValue.Length);
            }

            this.isEncryptor = isEncryptor;
        }
コード例 #4
0
        /// <remarks>Cloning can be very useful if you need multiple instances all using
        /// the same key, since the expensive cipher setup will be bypassed.</remarks>
        /// <see cref="System.ICloneable.Clone()"/>
        public object Clone()
        {
            BlowfishECB result = new BlowfishECB();

            result.pbox = (uint[])this.pbox.Clone();

            result.sbox1 = (uint[])this.sbox1.Clone();
            result.sbox2 = (uint[])this.sbox2.Clone();
            result.sbox3 = (uint[])this.sbox3.Clone();
            result.sbox4 = (uint[])this.sbox4.Clone();

            result.block = (byte[])this.block.Clone();

            result.isWeakKey = this.isWeakKey;

            return(result);
        }
コード例 #5
0
        /// <remarks>Cloning can be very useful if you need multiple instances all using
        /// the same key, since the expensive cipher setup will be bypassed.</remarks>
        /// <see cref="System.ICloneable.Clone()"/>
        public object Clone()
        {
            BlowfishECB result = new BlowfishECB();

            result.pbox = (uint[]) this.pbox.Clone();

            result.sbox1 = (uint[]) this.sbox1.Clone();
            result.sbox2 = (uint[]) this.sbox2.Clone();
            result.sbox3 = (uint[]) this.sbox3.Clone();
            result.sbox4 = (uint[]) this.sbox4.Clone();

            result.block = (byte[]) this.block.Clone();

            result.isWeakKey = this.isWeakKey;

            return result;
        }
コード例 #6
0
        /// <summary>To execute a selftest.</summary>
        /// <remarks>Call this method to make sure that the implemenation is able to produce
        /// valid output according to the specification. This should usually be done at process
        /// startup time, before the usage of this class and its inherited variants.</remarks>
        /// <returns>True if the selftest passed or false is it failed. In such a case you must
        /// not use the cipher to avoid data corruption!</returns>
        public static bool RunSelfTest()
        {
            uint hi = TEST_VECTOR_PLAIN[0];
            uint lo = TEST_VECTOR_PLAIN[1];

            BlowfishECB bfe = new BlowfishECB(TEST_KEY, 0, TEST_KEY.Length);

            bfe.EncryptBlock(hi, lo, out hi, out lo);

            if ((TEST_VECTOR_CIPHER[0] != hi) ||
                (TEST_VECTOR_CIPHER[1] != lo))
            {
                return false;
            }

            bfe.DecryptBlock(hi, lo, out hi, out lo);

            if ((TEST_VECTOR_PLAIN[0] != hi) ||
                (TEST_VECTOR_PLAIN[1] != lo))
            {
                return false;
            }

            return true;
        }