示例#1
0
        internal TwofishManagedTransform(byte[] key, CipherMode mode, byte[] iv, TwofishManagedTransformMode transformMode, PaddingMode paddingMode)
        {
            this.TransformMode = transformMode;
            this.PaddingMode   = paddingMode;

            var key32 = new uint[key.Length / 4];

            Buffer.BlockCopy(key, 0, key32, 0, key.Length);

            if (iv != null)
            {
                var iv32 = new uint[iv.Length / 4];
                Buffer.BlockCopy(iv, 0, iv32, 0, iv.Length);
                this.Implementation = new TwofishImplementation(key32, iv32, mode);
            }
            else
            {
                this.Implementation = new TwofishImplementation(key32, null, mode);
            }
        }
示例#2
0
        private ICryptoTransform NewEncryptor(byte[] rgbKey, CipherMode mode, byte[] rgbIV, TwofishManagedTransformMode encryptMode)
        {
            if (rgbKey == null)
            {
                rgbKey = new byte[this.KeySize / 8];
                Rng.Value.GetBytes(rgbKey);
            }

            if ((mode != CipherMode.ECB) && (rgbIV == null))
            {
                rgbIV = new byte[this.KeySize / 8];
                Rng.Value.GetBytes(rgbIV);
            }

            return(new TwofishManagedTransform(rgbKey, mode, rgbIV, encryptMode, this.Padding));
        }
示例#3
0
        //private static readonly Lazy<RandomNumberGenerator> Rng = new Lazy<RandomNumberGenerator>(() => RandomNumberGenerator.Create());

        private ICryptoTransform NewEncryptor(byte[] rgbKey, CipherMode mode, byte[] rgbIV, TwofishManagedTransformMode encryptMode)
        {
            if (rgbKey == null)
            {
                //rgbKey = new byte[KeySize / 8];
                //Rng.Value.GetBytes(rgbKey);
                throw new InvalidOperationException("Key is required");
            }

            if ((mode != CipherMode.ECB) && (rgbIV == null))
            {
                //rgbIV = new byte[KeySize / 8];
                //Rng.Value.GetBytes(rgbIV);
                throw new InvalidOperationException("IV is required");
            }

            return(new TwofishManagedTransform(rgbKey, mode, rgbIV, encryptMode, Padding));
        }