Org.BouncyCastle.Crypto.Engines.IesEngine.ProcessBlock C# (CSharp) Метод

ProcessBlock() публичный Метод

public ProcessBlock ( byte input, int inOff, int inLen ) : byte[]
input byte
inOff int
inLen int
Результат byte[]
        public byte[] ProcessBlock(
            byte[]  input,
            int     inOff,
            int     inLen)
        {
            agree.Init(privParam);

            BigInteger z = agree.CalculateAgreement(pubParam);

            // TODO Is a fixed length result expected?
            byte[] zBytes = z.ToByteArrayUnsigned();

            return forEncryption
                ?	EncryptBlock(input, inOff, inLen, zBytes)
                :	DecryptBlock(input, inOff, inLen, zBytes);
        }

Usage Example

Пример #1
0
		private void DoTest(
			AsymmetricCipherKeyPair	p1,
			AsymmetricCipherKeyPair	p2)
		{
			//
			// stream test
			//
			IesEngine i1 = new IesEngine(
				new ECDHBasicAgreement(),
				new Kdf2BytesGenerator(new Sha1Digest()),
				new HMac(new Sha1Digest()));
			IesEngine i2 = new IesEngine(
				new ECDHBasicAgreement(),
				new Kdf2BytesGenerator(new Sha1Digest()),
				new HMac(new Sha1Digest()));
			byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
			byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
			IesParameters  p = new IesParameters(d, e, 64);

			i1.Init(true, p1.Private, p2.Public, p);
			i2.Init(false, p2.Private, p1.Public, p);

			byte[] message = Hex.Decode("1234567890abcdef");

			byte[] out1 = i1.ProcessBlock(message, 0, message.Length);

			byte[] out2 = i2.ProcessBlock(out1, 0, out1.Length);

			if (!AreEqual(out2, message))
			{
				Fail("stream cipher test failed");
			}

			//
			// twofish with CBC
			//
			BufferedBlockCipher c1 = new PaddedBufferedBlockCipher(
				new CbcBlockCipher(new TwofishEngine()));
			BufferedBlockCipher c2 = new PaddedBufferedBlockCipher(
				new CbcBlockCipher(new TwofishEngine()));
			i1 = new IesEngine(
				new ECDHBasicAgreement(),
				new Kdf2BytesGenerator(new Sha1Digest()),
				new HMac(new Sha1Digest()),
				c1);
			i2 = new IesEngine(
				new ECDHBasicAgreement(),
				new Kdf2BytesGenerator(new Sha1Digest()),
				new HMac(new Sha1Digest()),
				c2);
			d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
			e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
			p = new IesWithCipherParameters(d, e, 64, 128);

			i1.Init(true, p1.Private, p2.Public, p);
			i2.Init(false, p2.Private, p1.Public, p);

			message = Hex.Decode("1234567890abcdef");

			out1 = i1.ProcessBlock(message, 0, message.Length);

			out2 = i2.ProcessBlock(out1, 0, out1.Length);

			if (!AreEqual(out2, message))
			{
				Fail("twofish cipher test failed");
			}
		}
All Usage Examples Of Org.BouncyCastle.Crypto.Engines.IesEngine::ProcessBlock