Example #1
0
 public void CheckE(string testName, byte[] key, byte[] data, byte[] result)
 {
     algo     = new HMACMD5();
     algo.Key = key;
     byte[] copy = new byte [data.Length];
     // LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
     for (int i = 0; i < data.Length - 1; i++)
     {
         algo.TransformBlock(data, i, 1, copy, i);
     }
     algo.TransformFinalBlock(data, data.Length - 1, 1);
     Assert.AreEqual(result, algo.Hash, testName + "e");
 }
Example #2
0
 public static byte[] HmacMd5(byte[] key, byte[] data, int offset, int length)
 {
     using HashAlgorithm hash = new HMACMD5(key);
     hash.TransformFinalBlock(data, offset, length);
     return(hash.Hash);
 }
        public void addElement(String s)
        {
            //word=binascii.a2b_qp(qgram) # convert to binary

            String mykey = "zuxujesw";

            byte[] keyBytes = Encoding.UTF8.GetBytes(mykey);
            String hex1     = "";
            String hex2     = "";

            try {
                HMACSHA1 mac = new HMACSHA1(keyBytes);
                mac.Initialize();
                byte[] inputBytes = new byte[s.Length];
                for (var i = 0; i < s.Length; i++)
                {
                    inputBytes.SetValue(Convert.ToByte(s[i]), i);//Encoding.UTF8.GetBytes(s);
                }
                byte[] digest = mac.TransformFinalBlock(inputBytes, 0, inputBytes.Length);
                hex1 = BitConverter.ToString(digest).Replace("-", string.Empty);
            } catch (Exception ex) {
                Console.Error.WriteLine("HMACSHA1: Hash error: " + ex.Message);
            }
            try {
                HMACMD5 mac = new HMACMD5(keyBytes);
                mac.Initialize();
                byte[] inputBytes = Encoding.UTF8.GetBytes(s);
                byte[] digest     = mac.TransformFinalBlock(inputBytes, 0, inputBytes.Length);
                hex2 = BitConverter.ToString(digest).Replace("-", string.Empty);
            } catch (Exception ex) {
                Console.Error.WriteLine("HMACMD5: Hash error: " + ex.Message);
            }
            // convert hash key to integer
            BigInteger h1 = BigInteger.Parse(hex1, NumberStyles.AllowHexSpecifier);
            BigInteger h2 = BigInteger.Parse(hex2, NumberStyles.AllowHexSpecifier);

            for (int i = 0; i < k; i++)
            {
                BigInteger bigi = new BigInteger(i);
                //BigInteger res = h2.multiply(bigi).add(h1).mod(new BigInteger(this.bitSetSize + ""));
                BigInteger res      = (h2 * bigi + h1) % new BigInteger(this.bitSetSize);
                int        position = (int)res;
                if (!bitset.get(position))
                {
                    bitsSet++;
                }
                if (bitset.get(position))
                {
                    if (cols[position] == 0)
                    {
                        cols[position] = 1;
                    }
                    else
                    {
                        cols[position] = cols[position] + 1;
                    }
                }
                bitset.set(position);
            }
            numberOfAddedElements++;
        }