Java Utililty Methods SHA

List of utility methods to do SHA

Description

The list of methods to do SHA are organized into topic(s).

Method

byte[]sha2(String... data)
sha
byte[] digest = new byte[32];
StringBuilder buffer = new StringBuilder();
for (String s : data) {
    buffer.append(s);
MessageDigest sha256 = null;
try {
    sha256 = MessageDigest.getInstance("SHA-256");
...
byte[]sha5Encode(byte[] content)
sha Encode
MessageDigest md = MessageDigest.getInstance("SHA-512");
byte[] mdRes = md.digest(content);
return mdRes;
byte[]SHA_1(byte[] input)
SH_
try {
    MessageDigest sha_1 = MessageDigest.getInstance("SHA-1");
    sha_1.update(input);
    return sha_1.digest();
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
return null;
...
StringshaFile(String paramString)
sha File
byte[] arrayOfByte = new byte[1024];
try {
    FileInputStream localFileInputStream = new FileInputStream(paramString);
    MessageDigest localMessageDigest = MessageDigest.getInstance("SHA-1");
    while (true) {
        int i = localFileInputStream.read(arrayOfByte);
        if (i <= 0) {
            localFileInputStream.close();
...
byte[]SHAHash(byte[] input)
Performs an SHA1 hash of an input byte array
try {
    final MessageDigest md = MessageDigest.getInstance("SHA-1");
    return md.digest(input);
} catch (final NoSuchAlgorithmException e) {
    e.printStackTrace();
return null;
StringshaHash(String message)
sha Hash
MessageDigest md = MessageDigest.getInstance("SHA-512");
byte[] hash = new byte[0];
hash = md.digest(message.getBytes());
StringBuilder sb = new StringBuilder(2 * hash.length);
for (byte b : hash)
    sb.append(String.format("%02x", b & 0xff));
return sb.toString();
StringshaPsw(String inputText)
sha Psw
return encrypt(inputText, "sha-1");
StringSHAsum(byte[] convertme)
SH Asum
try {
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    return "sha1:" + byteArray2Hex(md.digest(convertme));
} catch (NoSuchAlgorithmException e) {
    return "";
StringSHAsum(byte[] convertme, boolean prefix, boolean uppercase)
SH Asum
try {
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    String sha1 = byteArray2Hex(md.digest(convertme));
    if (prefix) {
        return "sha1:" + sha1;
    } else {
        if (uppercase) {
            return sha1.toUpperCase();
...
StringSHAsum(byte[] input)
Creates the SHA1 hash for a given array of bytes.
MessageDigest md;
try {
    md = MessageDigest.getInstance("SHA-1");
    return byteArray2Hex(md.digest(input));
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
return null;
...