SHA-1 hex dump

.NET, C#, Java, SHA-1, hashing

Jump to: navigation, search

Сабж.

// C#
using System.Security.Cryptography;
using System.Text;

public class SHA1Str {
    public static string Compute(string message) {
        SHA1 sha1 = SHA1CryptoServiceProvider.Create();
        byte[] hash = sha1.ComputeHash(Encoding.ASCII.GetBytes(message));
        StringBuilder digest = new StringBuilder();
        foreach (byte n in hash) digest.Append(n.ToString("x2"));
        return digest.ToString();
    }
}

// Java
import java.math.*;
import java.security.*;

public class SHA1Str {
    public static String compute(String message)
            throws NoSuchAlgorithmException {
        MessageDigest digest = MessageDigest.getInstance("SHA1");
        digest.update(message.getBytes(), 0, message.length());
        return new BigInteger(1, digest.digest()).toString(16);
    }
}

Personal tools
ссылка