SHA1 C # equivalent of this Java

Looking for the same equivalent to this method in C #

try { MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(password.getBytes()); BigInteger hash = new BigInteger(1, md.digest()); hashword = hash.toString(16); } catch (NoSuchAlgorithmException ex) { } } return hashword; 
+2
source share
2 answers

Super easy in C #:

 using System; using System.Text; using System.Security.Cryptography; namespace CSharpSandbox { class Program { public static string HashPassword(string input) { var sha1 = SHA1Managed.Create(); byte[] inputBytes = Encoding.ASCII.GetBytes(input); byte[] outputBytes = sha1.ComputeHash(inputBytes); return BitConverter.ToString(outputBytes).Replace("-", "").ToLower(); } public static void Main(string[] args) { string output = HashPassword("The quick brown fox jumps over the lazy dog"); } } } 
+3
source

Take a look at Sha1CryptoServiceProvider . This provides ample flexibility. Like most algorithms in System.Security.Cryptography , it provides methods for processing arrays and byte streams.

+1
source

Source: https://habr.com/ru/post/1315091/


All Articles