コード例 #1
0
ファイル: Crypt.cs プロジェクト: iFaxity/FaxLib
 // Creates a hash
 static byte[] ComputeHash(byte[] bytes, byte[] salt, HashType type, SHA3BitSize bitSize)
 {
     // Create a hash buffer with a salt
     if(salt != null && salt.Length > 0) {
         byte[] full = new byte[bytes.Length + salt.Length];
         for(int i = 0; i < bytes.Length; i++)
             full[i] = bytes[i];
         for(int i = 0; i < salt.Length; i++)
             full[bytes.Length + i] = salt[i];
         bytes = full;
     }
     // Identify the hash algorithm type
     HashAlgorithm crypt;
     switch(type) {
         case HashType.SHA1:
             crypt = new SHA1Managed();
             break;
         case HashType.SHA256:
             crypt = new SHA256Managed();
             break;
         case HashType.SHA512:
             crypt = new SHA512Managed();
             break;
         case HashType.SHA3:
             crypt = new SHA3.SHA3Managed((int)bitSize);
             break;
         case HashType.MD5:
             crypt = new MD5CryptoServiceProvider();
             break;
         default:
             throw new ArgumentException("Parameter invalid", "type");
     }
     return crypt.ComputeHash(bytes);
 }
コード例 #2
0
 public byte[] Hash(byte[] data)
 {
     SHA3.SHA3Managed sha3 = new SHA3.SHA3Managed(256);
     return(sha3.ComputeHash(data).Take(32).ToArray());
 }