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