Ejemplo n.º 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
			}
		}
Ejemplo n.º 2
0
        // signature
        public static string CreateSignature(string email, string password, RsaKeyParameters key)
        {
            
            byte[] prefix = { 0x00 };
            var keyStruct = KeyToStruct(key);
            var toEncrypt = Encoding.UTF8.GetBytes(email + "\x00" + password);
            var cipher = new OaepEncoding(new RsaEngine(), new Sha1Digest(), null);
            cipher.Init(true, key);
            var encrypted = cipher.ProcessBlock(toEncrypt, 0, toEncrypt.Length);

            var digest = new Sha1Digest();
            var hash = new byte[digest.GetByteLength()];
            digest.BlockUpdate(keyStruct, 0, keyStruct.Length);
            digest.DoFinal(hash, 0);
            var hashExcerpt = hash.Take(4).ToArray();

            return DataTypeUtils.UrlSafeBase64(DataTypeUtils.CombineBytes(prefix, hashExcerpt, encrypted));
        }