/// <summary> /// Creates the SRP-6a parameters using the specified hash function. /// </summary> /// <typeparam name="T"><see cref="HashAlgorithm"/> implementation.</typeparam> /// <param name="largeSafePrime">Large safe prime number N (hexadecimal).</param> /// <param name="generator">The generator value modulo N (hexadecimal).</param> /// <param name="paddedLength">The hexadecimal length of N and g.</param> /// <param name="revision">Revision of SRP protocol, defaults to 6a if not provided.</param> public static SrpParameters Create <T>(string largeSafePrime = null, string generator = null, int?paddedLength = null, SrpRevision?revision = null) where T : HashAlgorithm { var result = new SrpParameters { Hasher = new SrpHash <T>(), }; if (largeSafePrime != null) { result.Prime = SrpInteger.FromHex(largeSafePrime); result.PaddedLength = result.Prime.HexLength.Value; } if (generator != null) { result.Generator = SrpInteger.FromHex(generator); } if (paddedLength.HasValue) { result.PaddedLength = paddedLength.Value; } if (revision.HasValue) { result.Revision = revision.Value; } return(result); }
/// <summary> /// Checks if the given verifier value is a valid padded hexadecimal string. /// </summary> /// <param name="parameters">SRP parameters.</param> /// <param name="verifier">Password verifier.</param> /// <returns>True, if the verifier value is valid.</returns> public static bool IsValidVerifier(this SrpParameters parameters, string verifier) => IsValidInteger(verifier, parameters.PaddedLength);
/// <summary> /// Checks if the given salt value is a valid padded hexadecimal string. /// </summary> /// <param name="parameters">SRP parameters.</param> /// <param name="salt">Hexadecimal salt string.</param> /// <returns>True, if the salt value is valid.</returns> public static bool IsValidSalt(this SrpParameters parameters, string salt) => IsValidInteger(salt, parameters.HashSizeBytes * 2);
/// <summary> /// Initializes a new instance of the <see cref="SrpClient"/> class. /// </summary> /// <param name="parameters">The parameters of the SRP-6a protocol.</param> public SrpClient(SrpParameters parameters = null) { Parameters = parameters ?? new SrpParameters(); }
/// <summary> /// Initializes a new instance of the <see cref="SrpServer"/> class. /// </summary> /// <param name="parameters">The parameters of the SRP-6a protocol.</param> public SrpServer(SrpParameters parameters = null) { Parameters = parameters ?? new SrpParameters(); }