Org.BouncyCastle.Crypto.Digests.ShortenedDigest.DoFinal C# (CSharp) Method

DoFinal() public method

public DoFinal ( byte output, int outOff ) : int
output byte
outOff int
return int
		public int DoFinal(byte[] output, int outOff)
		{
			byte[] tmp = new byte[baseDigest.GetDigestSize()];

			baseDigest.DoFinal(tmp, 0);

	        Array.Copy(tmp, 0, output, outOff, length);

			return length;
		}

Usage Example

コード例 #1
0
		public override void PerformTest()
		{
			IDigest  d = new Sha1Digest();
			ShortenedDigest sd = new ShortenedDigest(new Sha1Digest(), 10);

			if (sd.GetDigestSize() != 10)
			{
				Fail("size check wrong for SHA-1");
			}

			if (sd.GetByteLength() != d.GetByteLength())
			{
				Fail("byte length check wrong for SHA-1");
			}

			//
			// check output fits
			//
			sd.DoFinal(new byte[10], 0);

			d = new Sha512Digest();
			sd = new ShortenedDigest(new Sha512Digest(), 20);

			if (sd.GetDigestSize() != 20)
			{
				Fail("size check wrong for SHA-512");
			}

			if (sd.GetByteLength() != d.GetByteLength())
			{
				Fail("byte length check wrong for SHA-512");
			}

			//
			// check output fits
			//
			sd.DoFinal(new byte[20], 0);

			try
			{
				new ShortenedDigest(null, 20);

				Fail("null parameter not caught");
			}
			catch (ArgumentException)
			{
				// expected
			}

			try
			{
				new ShortenedDigest(new Sha1Digest(), 50);

				Fail("short digest not caught");
			}
			catch (ArgumentException)
			{
				// expected
			}
		}