Example #1
0
 public static string ArgonHashString(string password, long opsLimit, int memLimit)
 {
     if (password == null)
     {
         throw new ArgumentNullException("password", "Password cannot be null");
     }
     if (opsLimit < 3L)
     {
         throw new ArgumentOutOfRangeException("opsLimit", "opsLimit the number of passes, has to be at least 3");
     }
     if (memLimit <= 0)
     {
         throw new ArgumentOutOfRangeException("memLimit", "memLimit cannot be zero or negative");
     }
     byte[] array = new byte[128];
     byte[] bytes = Encoding.UTF8.GetBytes(password);
     if (SodiumLibrary.crypto_pwhash_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));
 }