Esempio n. 1
0
 public static string ScryptHashString(string password, long opsLimit, int memLimit)
 {
     if (password == null)
     {
         throw new ArgumentNullException("password", "Password cannot be null");
     }
     if (opsLimit <= 0L)
     {
         throw new ArgumentOutOfRangeException("opsLimit", "opsLimit cannot be zero or negative");
     }
     if (memLimit <= 0)
     {
         throw new ArgumentOutOfRangeException("memLimit", "memLimit cannot be zero or negative");
     }
     byte[] array = new byte[102];
     byte[] bytes = Encoding.UTF8.GetBytes(password);
     if (SodiumLibrary.crypto_pwhash_scryptsalsa208sha256_str(array, bytes, (long)bytes.Length, opsLimit, memLimit) != 0)
     {
         throw new OutOfMemoryException("Internal error, hash failed (usually because the operating system refused to allocate the amount of requested memory).");
     }
     return(Encoding.UTF8.GetString(array));
 }