/// <summary> /// Get the hashcode from the value. /// </summary> /// <param name="value">The value to generate the hash code for.</param> /// <param name="hashcodeType">The hash name.</param> /// <param name="keySizePBKDF2">The PBKDF2 key size to generate.</param> /// <returns>The generated hash code.</returns> public static byte[] GetHashcodeRaw(string value, Nequeo.Cryptography.HashcodeType hashcodeType, int keySizePBKDF2 = 100) { // Generate the hash code HashAlgorithm alg = null; // Select the hash code type. switch (hashcodeType) { case HashcodeType.SHA3: // SHA3 hashcode. alg = new Sha3.SHA3Managed(); break; case HashcodeType.PBKDF2: // PBKDF2 hashcode. byte[] hashValueEx = RandomDerivedKey.GenerateEx(value, keySizePBKDF2, 5000); return(hashValueEx); default: alg = HashAlgorithm.Create(hashcodeType.ToString()); break; } byte[] byteValue = Encoding.ASCII.GetBytes(value); byte[] hashValue = alg.ComputeHash(byteValue); return(hashValue); }
/// <summary> /// Get the hashcode from the value. /// </summary> /// <param name="value">The value to generate the hash code for.</param> /// <param name="hashcodeType">The hash name.</param> /// <returns>The generated hash code.</returns> public static byte[] GetHashcodeRaw(string value, Nequeo.Cryptography.HashcodeType hashcodeType) { // Generate the hash code HashAlgorithm alg = HashAlgorithm.Create(hashcodeType.ToString()); byte[] byteValue = Encoding.ASCII.GetBytes(value); byte[] hashValue = alg.ComputeHash(byteValue); return(hashValue); }
/// <summary> /// Get the hashcode from the value. /// </summary> /// <param name="value">The value to generate the hash code for.</param> /// <param name="hashcodeType">The hash name.</param> /// <returns>The generated hash code.</returns> public static string GetHashcode(string value, Nequeo.Cryptography.HashcodeType hashcodeType) { int i = 0; // Generate the hash code HashAlgorithm alg = HashAlgorithm.Create(hashcodeType.ToString()); byte[] byteValue = Encoding.ASCII.GetBytes(value); byte[] hashValue = alg.ComputeHash(byteValue); // Get the string value of hashcode. string[] octetArrayByte = new string[hashValue.Count()]; foreach (Byte item in hashValue) { octetArrayByte[i++] = item.ToString("X2"); } // Create the octet string of bytes. string octetValue = String.Join("", octetArrayByte); return(octetValue); }