} // SecurityKeyFromPemFile. private static void CompareSha256Implementations(string source) { int len = source.Length; WriteLine($"\nSource string to be SHA-256 hashed: <{source}> ({len})"); string hashA; string hashB; // Compute hash using .NET Core implemenatation: using (SHA256 sha256Hash = SHA256.Create()) { hashA = GetHash(sha256Hash, source); WriteLine($"The .NET Core SHA256 class hash is: <{hashA}>"); } // Compute hash using in source implemenatation: hashB = Sha2.GetHash(source); WriteLine($"The in source implemented hash is: <{hashB}>"); } // CompareSha256Implementations.
} // CompareSha256Implementations. private static void SeekForSha2ForbiddenStringLength(int lower, int upper) { WriteLine($"\nSeeking for Sha2 forbidden string lengths ({lower},{upper}):"); int found = 0; for (int len = lower; len <= upper; len++) { // generate random string of given length: string source = RandomString(len); string hashA; string hashB; // Compute hash using .NET Core implemenatation: using (SHA256 sha256Hash = SHA256.Create()) { hashA = GetHash(sha256Hash, source); } // Compute hash using in source implemenatation: hashB = Sha2.GetHash(source); // Compare resualts: if (!String.Equals(hashA, hashB)) { // Report forbidden string length: Write($"{len} "); if (++found % 8 == 0) { WriteLine(); } } } // for. if (found == 0) { WriteLine($"No forbidden string length found."); } } // SeekForForbiddenStringLength.