Esempio n. 1
0
        public static string HmacSign(string aValue, string aKey)
        {
            var kIpad = new byte[64];
            var kOpad = new byte[64];
            byte[] keyb = Encoding.UTF8.GetBytes(aKey);
            byte[] value = Encoding.UTF8.GetBytes(aValue);

            for (int i = keyb.Length; i < 64; i++)
                kIpad[i] = 54;

            for (int i = keyb.Length; i < 64; i++)
                kOpad[i] = 92;

            for (int i = 0; i < keyb.Length; i++)
            {
                kIpad[i] = (byte)(keyb[i] ^ 0x36);
                kOpad[i] = (byte)(keyb[i] ^ 0x5c);
            }

            var md = new HmacMd5();

            md.Update(kIpad, (uint)kIpad.Length);
            md.Update(value, (uint)value.Length);
            byte[] dg = md.Finalize();
            md.Init();
            md.Update(kOpad, (uint)kOpad.Length);
            md.Update(dg, 16);
            dg = md.Finalize();

            return ToHex(dg);
        }
Esempio n. 2
0
        public static string HmacSign(string aValue, string aKey)
        {
            var kIpad = new byte[64];
            var kOpad = new byte[64];

            byte[] keyb  = Encoding.UTF8.GetBytes(aKey);
            byte[] value = Encoding.UTF8.GetBytes(aValue);

            for (int i = keyb.Length; i < 64; i++)
            {
                kIpad[i] = 54;
            }

            for (int i = keyb.Length; i < 64; i++)
            {
                kOpad[i] = 92;
            }

            for (int i = 0; i < keyb.Length; i++)
            {
                kIpad[i] = (byte)(keyb[i] ^ 0x36);
                kOpad[i] = (byte)(keyb[i] ^ 0x5c);
            }

            var md = new HmacMd5();

            md.Update(kIpad, (uint)kIpad.Length);
            md.Update(value, (uint)value.Length);
            byte[] dg = md.Finalize();
            md.Init();
            md.Update(kOpad, (uint)kOpad.Length);
            md.Update(dg, 16);
            dg = md.Finalize();

            return(ToHex(dg));
        }