示例#1
0
        /// <summary>Derives a secret key of any size from a password and a salt.</summary>
        /// <param name="password">The password.</param>
        /// <param name="salt">The salt.</param>
        /// <param name="limit">The limit for computation.</param>
        /// <param name="outputLength">The length of the computed output array.</param>
        /// <returns>Returns a byte array of the given size.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="SaltOutOfRangeException"></exception>
        /// <exception cref="OutOfMemoryException"></exception>
        public static byte[] ArgonHashBinary(byte[] password, byte[] salt,
                                             StrengthArgon limit = StrengthArgon.Interactive, long outputLength = ARGON_SALTBYTES)
        {
            int  memLimit;
            long opsLimit;

            switch (limit)
            {
            case StrengthArgon.Interactive:
                opsLimit = ARGON_OPSLIMIT_INTERACTIVE;
                memLimit = ARGON_MEMLIMIT_INTERACTIVE;
                break;

            case StrengthArgon.Moderate:
                opsLimit = ARGON_OPSLIMIT_MODERATE;
                memLimit = ARGON_MEMLIMIT_MODERATE;
                break;

            case StrengthArgon.Sensitive:
                opsLimit = ARGON_OPSLIMIT_SENSITIVE;
                memLimit = ARGON_MEMLIMIT_SENSITIVE;
                break;

            default:
                opsLimit = ARGON_OPSLIMIT_INTERACTIVE;
                memLimit = ARGON_MEMLIMIT_INTERACTIVE;
                break;
            }

            return(ArgonHashBinary(password, salt, opsLimit, memLimit, outputLength));
        }
示例#2
0
        /// <summary>Returns the hash in a string format, which includes the generated salt.</summary>
        /// <param name="password">The password.</param>
        /// <param name="limit">The limit for computation.</param>
        /// <returns>Returns an zero-terminated ASCII encoded string of the computed password and hash.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="OutOfMemoryException"></exception>
        public static string ArgonHashString(string password, StrengthArgon limit = StrengthArgon.Interactive)
        {
            int  memLimit;
            long opsLimit;

            switch (limit)
            {
            case StrengthArgon.Interactive:
                opsLimit = ARGON_OPSLIMIT_INTERACTIVE;
                memLimit = ARGON_MEMLIMIT_INTERACTIVE;
                break;

            case StrengthArgon.Moderate:
                opsLimit = ARGON_OPSLIMIT_MODERATE;
                memLimit = ARGON_MEMLIMIT_MODERATE;
                break;

            case StrengthArgon.Sensitive:
                opsLimit = ARGON_OPSLIMIT_SENSITIVE;
                memLimit = ARGON_MEMLIMIT_SENSITIVE;
                break;

            default:
                opsLimit = ARGON_OPSLIMIT_INTERACTIVE;
                memLimit = ARGON_MEMLIMIT_INTERACTIVE;
                break;
            }

            return(ArgonHashString(password, opsLimit, memLimit));
        }
        private static (long opsLimit, int memLimit) GetArgonOpsAndMemoryLimit(StrengthArgon limit = StrengthArgon.Interactive)
        {
            int  memLimit;
            long opsLimit;

            switch (limit)
            {
            case StrengthArgon.Interactive:
                opsLimit = ARGON_OPSLIMIT_INTERACTIVE;
                memLimit = ARGON_MEMLIMIT_INTERACTIVE;
                break;

            case StrengthArgon.Medium:
                opsLimit = ARGON_OPSLIMIT_MEDIUM;
                memLimit = ARGON_MEMLIMIT_MEDIUM;
                break;

            case StrengthArgon.Moderate:
                opsLimit = ARGON_OPSLIMIT_MODERATE;
                memLimit = ARGON_MEMLIMIT_MODERATE;
                break;

            case StrengthArgon.Sensitive:
                opsLimit = ARGON_OPSLIMIT_SENSITIVE;
                memLimit = ARGON_MEMLIMIT_SENSITIVE;
                break;

            default:
                opsLimit = ARGON_OPSLIMIT_INTERACTIVE;
                memLimit = ARGON_MEMLIMIT_INTERACTIVE;
                break;
            }
            return(opsLimit, memLimit);
        }
        /// <summary>Derives a secret key of any size from a password and a salt.</summary>
        /// <param name="password">The password.</param>
        /// <param name="salt">The salt.</param>
        /// <param name="limit">The limit for computation.</param>
        /// <param name="outputLength">The length of the computed output array.</param>
        /// <param name="alg">Argon Algorithm</param>
        /// <returns>Returns a byte array of the given size.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="SaltOutOfRangeException"></exception>
        /// <exception cref="OutOfMemoryException"></exception>
        public static byte[] ArgonHashBinary(byte[] password, byte[] salt, StrengthArgon limit = StrengthArgon.Interactive, long outputLength = ARGON_SALTBYTES,
                                             ArgonAlgorithm alg = ArgonAlgorithm.Argon_2I13)
        {
            var(opsLimit, memLimit) = GetArgonOpsAndMemoryLimit(limit);

            return(ArgonHashBinary(password, salt, opsLimit, memLimit, outputLength, alg));
        }
示例#5
0
 /// <summary>Derives a secret key of any size from a password and a salt.</summary>
 /// <param name="password">The password.</param>
 /// <param name="salt">The salt.</param>
 /// <param name="limit">The limit for computation.</param>
 /// <param name="outputLength">The length of the computed output array.</param>
 /// <param name="alg">Argon Algorithm</param>
 /// <returns>Returns a byte array of the given size.</returns>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ArgumentOutOfRangeException"></exception>
 /// <exception cref="SaltOutOfRangeException"></exception>
 /// <exception cref="OutOfMemoryException"></exception>
 public static byte[] ArgonHashBinary(string password, string salt, StrengthArgon limit = StrengthArgon.Interactive, long outputLength = ARGON_SALTBYTES,
                                      ArgonAlgorithm alg = ArgonAlgorithm.Argon_2I13)
 {
     return(ArgonHashBinary(Encoding.UTF8.GetBytes(password), Encoding.UTF8.GetBytes(salt), limit, outputLength, alg));
 }
 /// <summary>Derives a secret key of any size from a password and a salt.</summary>
 /// <param name="password">The password.</param>
 /// <param name="salt">The salt.</param>
 /// <param name="limit">The limit for computation.</param>
 /// <param name="outputLength">The length of the computed output array.</param>
 /// <returns>Returns a byte array of the given size.</returns>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ArgumentOutOfRangeException"></exception>
 /// <exception cref="SaltOutOfRangeException"></exception>
 /// <exception cref="OutOfMemoryException"></exception>
 public static byte[] ArgonHashBinary(string password, string salt,
                                      StrengthArgon limit = StrengthArgon.INTERACTIVE, long outputLength = ARGON_SALTBYTES)
 {
     return(ArgonHashBinary(Encoding.UTF8.GetBytes(password), Encoding.UTF8.GetBytes(salt), limit, outputLength));
 }
 public static bool ArgonPasswordNeedsRehash(string password, StrengthArgon limit = StrengthArgon.Interactive)
 {
     return(ArgonPasswordNeedsRehash(Encoding.UTF8.GetBytes(password), limit));
 }
        public static bool ArgonPasswordNeedsRehash(byte[] password, StrengthArgon limit = StrengthArgon.Interactive)
        {
            var(opsLimit, memLimit) = GetArgonOpsAndMemoryLimit(limit);

            return(ArgonPasswordNeedsRehash(password, opsLimit, memLimit));
        }
        /// <summary>Returns the hash in a string format, which includes the generated salt.</summary>
        /// <param name="password">The password.</param>
        /// <param name="limit">The limit for computation.</param>
        /// <returns>Returns an zero-terminated ASCII encoded string of the computed password and hash.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="OutOfMemoryException"></exception>
        public static string ArgonHashString(string password, StrengthArgon limit = StrengthArgon.Interactive)
        {
            var(opsLimit, memLimit) = GetArgonOpsAndMemoryLimit(limit);

            return(ArgonHashString(password, opsLimit, memLimit));
        }
示例#10
0
        /// <summary>Returns the hash in a string format, which includes the generated salt.</summary>
        /// <param name="password">The password.</param>
        /// <param name="limit">The limit for computation.</param>
        /// <returns>Returns an zero-terminated ASCII encoded string of the computed password and hash.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="OutOfMemoryException"></exception>
        public static string ArgonHashString(string password, StrengthArgon limit = StrengthArgon.Interactive)
        {
            int memLimit;
              long opsLimit;

              switch (limit)
              {
            case StrengthArgon.Interactive:
              opsLimit = ARGON_OPSLIMIT_INTERACTIVE;
              memLimit = ARGON_MEMLIMIT_INTERACTIVE;
              break;
            case StrengthArgon.Moderate:
              opsLimit = ARGON_OPSLIMIT_MODERATE;
              memLimit = ARGON_MEMLIMIT_MODERATE;
              break;
            case StrengthArgon.Sensitive:
              opsLimit = ARGON_OPSLIMIT_SENSITIVE;
              memLimit = ARGON_MEMLIMIT_SENSITIVE;
              break;
            default:
              opsLimit = ARGON_OPSLIMIT_INTERACTIVE;
              memLimit = ARGON_MEMLIMIT_INTERACTIVE;
              break;
              }

              return ArgonHashString(password, opsLimit, memLimit);
        }
示例#11
0
        /// <summary>Derives a secret key of any size from a password and a salt.</summary>
        /// <param name="password">The password.</param>
        /// <param name="salt">The salt.</param>
        /// <param name="limit">The limit for computation.</param>
        /// <param name="outputLength">The length of the computed output array.</param>
        /// <returns>Returns a byte array of the given size.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="SaltOutOfRangeException"></exception>
        /// <exception cref="OutOfMemoryException"></exception>
        public static byte[] ArgonHashBinary(byte[] password, byte[] salt, StrengthArgon limit = StrengthArgon.Interactive, long outputLength = ARGON_SALTBYTES)
        {
            int memLimit;
              long opsLimit;

              switch (limit)
              {
            case StrengthArgon.Interactive:
              opsLimit = ARGON_OPSLIMIT_INTERACTIVE;
              memLimit = ARGON_MEMLIMIT_INTERACTIVE;
              break;
            case StrengthArgon.Moderate:
              opsLimit = ARGON_OPSLIMIT_MODERATE;
              memLimit = ARGON_MEMLIMIT_MODERATE;
              break;
            case StrengthArgon.Sensitive:
              opsLimit = ARGON_OPSLIMIT_SENSITIVE;
              memLimit = ARGON_MEMLIMIT_SENSITIVE;
              break;
            default:
              opsLimit = ARGON_OPSLIMIT_INTERACTIVE;
              memLimit = ARGON_MEMLIMIT_INTERACTIVE;
              break;
              }

              return ArgonHashBinary(password, salt, opsLimit, memLimit, outputLength);
        }
示例#12
0
 /// <summary>Derives a secret key of any size from a password and a salt.</summary>
 /// <param name="password">The password.</param>
 /// <param name="salt">The salt.</param>
 /// <param name="limit">The limit for computation.</param>
 /// <param name="outputLength">The length of the computed output array.</param>
 /// <returns>Returns a byte array of the given size.</returns>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ArgumentOutOfRangeException"></exception>
 /// <exception cref="SaltOutOfRangeException"></exception>
 /// <exception cref="OutOfMemoryException"></exception>
 public static byte[] ArgonHashBinary(string password, string salt, StrengthArgon limit = StrengthArgon.Interactive, long outputLength = ARGON_SALTBYTES)
 {
     return ArgonHashBinary(Encoding.UTF8.GetBytes(password), Encoding.UTF8.GetBytes(salt), limit, outputLength);
 }