Org.BouncyCastle.Crypto.Modes.CfbBlockCipher.Init C# (CSharp) Method

Init() public method

public Init ( bool forEncryption, ICipherParameters parameters ) : void
forEncryption bool
parameters ICipherParameters
return void
        public void Init(
            bool forEncryption,
            ICipherParameters parameters)
        {
            this.encrypting = forEncryption;
            if (parameters is ParametersWithIV)
            {
                ParametersWithIV ivParam = (ParametersWithIV) parameters;
                byte[] iv = ivParam.GetIV();
                int diff = IV.Length - iv.Length;
                Array.Copy(iv, 0, IV, diff, iv.Length);
                Array.Clear(IV, 0, diff);

                parameters = ivParam.Parameters;
            }
            Reset();
            cipher.Init(true, parameters);
        }
        /**

Usage Example

Example #1
0
		public virtual ITestResult Perform()
		{
			KeyParameter key = new KeyParameter(Hex.Decode("0011223344556677"));
			byte[] input = Hex.Decode("4e6f7720");
			byte[] out1 = new byte[4];
			byte[] out2 = new byte[4];


			IBlockCipher ofb = new OfbBlockCipher(new DesEngine(), 32);

			ofb.Init(true, new ParametersWithIV(key, Hex.Decode("1122334455667788")));

			ofb.ProcessBlock(input, 0, out1, 0);

			ofb.Init(false, new ParametersWithIV(key, Hex.Decode("1122334455667788")));
			ofb.ProcessBlock(out1, 0, out2, 0);

			if (!Arrays.AreEqual(out2, input))
			{
				return new SimpleTestResult(false, Name + ": test 1 - in != out");
			}

			ofb.Init(true, new ParametersWithIV(key, Hex.Decode("11223344")));

			ofb.ProcessBlock(input, 0, out1, 0);

			ofb.Init(false, new ParametersWithIV(key, Hex.Decode("0000000011223344")));
			ofb.ProcessBlock(out1, 0, out2, 0);

			if (!Arrays.AreEqual(out2, input))
			{
				return new SimpleTestResult(false, Name + ": test 2 - in != out");
			}

			IBlockCipher cfb = new CfbBlockCipher(new DesEngine(), 32);

			cfb.Init(true, new ParametersWithIV(key, Hex.Decode("1122334455667788")));

			cfb.ProcessBlock(input, 0, out1, 0);

			cfb.Init(false, new ParametersWithIV(key, Hex.Decode("1122334455667788")));
			cfb.ProcessBlock(out1, 0, out2, 0);

			if (!Arrays.AreEqual(out2, input))
			{
				return new SimpleTestResult(false, Name + ": test 3 - in != out");
			}

			cfb.Init(true, new ParametersWithIV(key, Hex.Decode("11223344")));

			cfb.ProcessBlock(input, 0, out1, 0);

			cfb.Init(false, new ParametersWithIV(key, Hex.Decode("0000000011223344")));
			cfb.ProcessBlock(out1, 0, out2, 0);

			if (!Arrays.AreEqual(out2, input))
			{
				return new SimpleTestResult(false, Name + ": test 4 - in != out");
			}

			return new SimpleTestResult(true, Name + ": Okay");
		}
All Usage Examples Of Org.BouncyCastle.Crypto.Modes.CfbBlockCipher::Init