Esempio n. 1
0
 /// <summary>
 /// Return a new TpmHash that is the hash of random data
 /// </summary>
 /// <param name="hashAlg"></param>
 /// <returns></returns>
 public static TpmHash FromRandom(TpmAlgId hashAlg)
 {
     if (!CryptoLib.IsHashAlgorithm(hashAlg))
     {
         Globs.Throw <ArgumentException>("TpmHash.FromRandom: Not a hash algorithm");
     }
     return(new TpmHash(hashAlg, CryptoLib.HashData(hashAlg, Globs.GetRandomBytes((int)DigestSize(hashAlg)))));
 }
Esempio n. 2
0
 /// <summary>
 /// Return a TpmHash that is the hash of Encoding.Unicode.GetBytes(password)
 /// </summary>
 /// <param name="hashAlg"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public static TpmHash FromString(TpmAlgId hashAlg, string password)
 {
     if (!CryptoLib.IsHashAlgorithm(hashAlg))
     {
         Globs.Throw <ArgumentException>("TpmHash.FromString: Not a hash algorithm");
     }
     return(new TpmHash(hashAlg, CryptoLib.HashData(hashAlg, Encoding.Unicode.GetBytes(password))));
 }
Esempio n. 3
0
 /// <summary>
 /// Return a new TpmHash set to the hash of the supplied data
 /// </summary>
 /// <param name="hashAlg"></param>
 /// <param name="dataToHash"></param>
 /// <returns></returns>
 public static TpmHash FromData(TpmAlgId hashAlg, byte[] dataToHash)
 {
     if (!CryptoLib.IsHashAlgorithm(hashAlg))
     {
         Globs.Throw <ArgumentException>("TpmHash.FromData: Not a hash algorithm");
     }
     return(new TpmHash(hashAlg, CryptoLib.HashData(hashAlg, dataToHash)));
 }