public string CalculateHMAC(string iPut, string uName,string HMACKey)
        {
            byte[] array = Encoding.UTF8.GetBytes(iPut + "/" + uName);
            byte[] output = new byte[256];

            IDigest dig = DigestUtilities.GetDigest("SHA256");
            HMac hm = new HMac(dig);
            byte[] keyArray = Base32Encoder.Decode(HMACKey);
            hm.BlockUpdate(array, 0, array.Length);
            hm.Init(new KeyParameter(keyArray, 0, keyArray.Length));
            int len = hm.DoFinal(output, 0);
            return Base32Encoder.Encode(output);
        }
 public static string Signature(string httpmethod, string url, string parameterString, string oauthToken)
 {
     string baseString = httpmethod.ToUpper() + "&" + PercentEncode(url) + "&" + PercentEncode(parameterString);
     string signingKey = PercentEncode(consumerSecret) + "&" + PercentEncode(oauthToken);
     var sha = new HMac(new Sha1Digest());
     sha.Init(new KeyParameter(Encoding.UTF8.GetBytes(signingKey)));
     var data = Encoding.UTF8.GetBytes(baseString);
     sha.BlockUpdate(data, 0, data.Length);
     byte[] result = new byte[20];
     sha.DoFinal(result, 0);
     return Convert.ToBase64String(result);
 }
Esempio n. 3
0
		private static void hmac_hash(IDigest digest, byte[] secret, byte[] seed, byte[] output)
		{
			HMac mac = new HMac(digest);
			KeyParameter param = new KeyParameter(secret);
			byte[] a = seed;
			int size = digest.GetDigestSize();
			int iterations = (output.Length + size - 1) / size;
			byte[] buf = new byte[mac.GetMacSize()];
			byte[] buf2 = new byte[mac.GetMacSize()];
			for (int i = 0; i < iterations; i++)
			{
				mac.Init(param);
				mac.BlockUpdate(a, 0, a.Length);
				mac.DoFinal(buf, 0);
				a = buf;
				mac.Init(param);
				mac.BlockUpdate(a, 0, a.Length);
				mac.BlockUpdate(seed, 0, seed.Length);
				mac.DoFinal(buf2, 0);
				Array.Copy(buf2, 0, output, (size * i), System.Math.Min(size, output.Length - (size * i)));
			}
		}