Created
November 9, 2019 13:36
-
-
Save kyrathasoft/42752934c7ca73261272543e522b5273 to your computer and use it in GitHub Desktop.
computer SHA1 and MD5 hashes of strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//requires using System.Security.Cryptography; | |
static string GetSHA1 (string ipString) { | |
SHA1 sha1 = new SHA1CryptoServiceProvider (); | |
byte[] ipBytes = Encoding.Default.GetBytes (ipString.ToCharArray ()); | |
byte[] opBytes = sha1.ComputeHash (ipBytes); | |
StringBuilder stringBuilder = new StringBuilder (40); | |
for (int i = 0; i < opBytes.Length; i++) { | |
stringBuilder.Append (opBytes[i].ToString ("x2")); | |
} | |
return stringBuilder.ToString (); | |
} | |
static string GetMD5 (string ipString) { | |
MD5 md5 = new MD5CryptoServiceProvider (); | |
byte[] ipBytes = Encoding.Default.GetBytes (ipString.ToCharArray ()); | |
byte[] opBytes = md5.ComputeHash (ipBytes); | |
StringBuilder stringBuilder = new StringBuilder (40); | |
for (int i = 0; i < opBytes.Length; i++) { | |
stringBuilder.Append (opBytes[i].ToString ("x2")); | |
} | |
return stringBuilder.ToString (); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment