示例#1
0
 public static byte[] ArgonHashBinary(byte[] password, byte[] salt, long opsLimit, int memLimit, long outputLength = 16L)
 {
     if (password == null)
     {
         throw new ArgumentNullException("password", "Password cannot be null");
     }
     if (salt == null)
     {
         throw new ArgumentNullException("salt", "Salt cannot be null");
     }
     if ((long)salt.Length != 16L)
     {
         throw new SaltOutOfRangeException(string.Format("Salt must be {0} bytes in length.", 16u));
     }
     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");
     }
     if (outputLength <= 0L)
     {
         throw new ArgumentOutOfRangeException("outputLength", "OutputLength cannot be zero or negative");
     }
     byte[] array = new byte[outputLength];
     if (SodiumLibrary.crypto_pwhash(array, (long)array.Length, password, (long)password.Length, salt, opsLimit, memLimit, 1) != 0)
     {
         throw new OutOfMemoryException("Internal error, hash failed (usually because the operating system refused to allocate the amount of requested memory).");
     }
     return(array);
 }