Пример #1
0
        static IBlockCipher Setup(IBlockCipher algo, string mode, bool encryption, byte[] key, byte[] iv)
        {
            if (mode == "ECB")
            {
                algo.Init(encryption, new KeyParameter(key));
                return(algo);
            }
            IBlockCipher cipher = null;

            if (mode == "CBC")
            {
                cipher = new Org.BouncyCastle.Crypto.Modes.CbcBlockCipher(algo);
            }
            if (mode == "CFB")
            {
                cipher = new Org.BouncyCastle.Crypto.Modes.CfbBlockCipher(algo, iv.Length << 3);
            }
            if (mode == "OFB")
            {
                cipher = new Org.BouncyCastle.Crypto.Modes.OfbBlockCipher(algo, iv.Length);
            }
            if (cipher != null)
            {
                cipher.Init(encryption, new ParametersWithIV(new KeyParameter(key), iv));
                return(cipher);
            }
            throw new ArgumentException();
        }
Пример #2
0
		static IBlockCipher Setup (IBlockCipher algo, string mode, bool encryption, byte[] key, byte[] iv)
		{
			if (mode == "ECB") {
				algo.Init (encryption, new KeyParameter (key));
				return algo;
			}
			IBlockCipher cipher = null;
			if (mode == "CBC") cipher = new Org.BouncyCastle.Crypto.Modes.CbcBlockCipher (algo);
			if (mode == "CFB") cipher = new Org.BouncyCastle.Crypto.Modes.CfbBlockCipher (algo, iv.Length << 3);
			if (mode == "OFB") cipher = new Org.BouncyCastle.Crypto.Modes.OfbBlockCipher (algo, iv.Length);
			if (cipher != null) {
				cipher.Init (encryption, new ParametersWithIV (new KeyParameter (key), iv));
				return cipher;
			}
			throw new ArgumentException ();
		}