Example #1
0
 public static Hmac MD5(byte[] key)
 {
     return(new Hmac(Digest.MD5(), key));
 }
Example #2
0
 void Hash(Digest digest, object value, bool deep)
 {
     if (value != null)
     {
         var type = value.GetType();
         if (type.IsArray || (value is IList))
         {
             var enumerator = AOT.GetEnumerator(value);
             if (enumerator != null)
             {
                 while (enumerator.MoveNext())
                 {
                     Hash(digest, enumerator.Current, deep);
                 }
             }
         }
         else if (value is IDictionary)
         {
             var enumerator = AOT.GetDictionaryEnumerator(value);
             if (enumerator != null)
             {
                 while (enumerator.MoveNext())
                 {
                     Hash(digest, enumerator.Key, deep);
                     Hash(digest, enumerator.Value, deep);
                 }
             }
         }
         else if (type == typeof(int))
         {
             digest.Update(System.BitConverter.GetBytes((int)value));
         }
         else if (type == typeof(uint))
         {
             digest.Update(System.BitConverter.GetBytes((uint)value));
         }
         else if (type == typeof(bool))
         {
             digest.Update(System.BitConverter.GetBytes((bool)value));
         }
         else if (type == typeof(ushort))
         {
             digest.Update(System.BitConverter.GetBytes((ushort)value));
         }
         else if (type == typeof(short))
         {
             digest.Update(System.BitConverter.GetBytes((short)value));
         }
         else if (type == typeof(float))
         {
             digest.Update(System.BitConverter.GetBytes((float)value));
         }
         else if (type == typeof(double))
         {
             digest.Update(System.BitConverter.GetBytes((double)value));
         }
         else if (type == typeof(ulong))
         {
             digest.Update(System.BitConverter.GetBytes((ulong)value));
         }
         else if (type == typeof(long))
         {
             digest.Update(System.BitConverter.GetBytes((uint)value));
         }
         else if (type == typeof(string))
         {
             digest.Update(Encoding.GetBytes((string)value));
         }
         else if (type.IsEnum)
         {
             digest.Update(System.BitConverter.GetBytes(System.Convert.ToInt32(value)));
         }
         else if (type.IsClass && deep)
         {
             var info = GetTypeInfo(type);
             info._GetHash(digest, value, deep);
         }
     }
 }
Example #3
0
 public static Hmac Sha1(byte[] key)
 {
     return(new Hmac(Digest.Sha1(), key));
 }