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[]sha(byte data[])
sha
return getShaDigest().digest(data);
byte[]sha(byte[] data)
Calculates the SHA digest and returns the symbol as a byte[].
return getSHA().digest(data);
StringSHA(String s)
SHA
try {
    MessageDigest md = MessageDigest.getInstance("SHA");
    md.update(s.getBytes(), 0, s.getBytes().length);
    byte[] hash = md.digest();
    StringBuilder sb = new StringBuilder();
    int msb;
    int lsb = 0;
    int i;
...
Stringsha(String source)
Converts a java.lang.String in to a SHA hashed String
try {
    MessageDigest md = MessageDigest.getInstance("SHA");
    byte[] bytes = md.digest(source.getBytes());
    return getString(bytes);
} catch (Exception e) {
    e.printStackTrace();
    return null;
Stringsha(String str)
sha
return encode(str, "SHA");
byte[]sha(String strPlain)
sha
byte s[] = null;
try {
    MessageDigest m = MessageDigest.getInstance("SHA-1");
    s = m.digest(strPlain.getBytes("utf-8"));
} catch (Exception e) {
    throw new RuntimeException(e);
return s;
...
Stringsha(String text, String encoding)
sha
return encryptPassword(text, encoding, "sha");
Stringsha2(String content)
sha
try {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    byte[] thedigest = md.digest(content.getBytes());
    char chars[] = new char[32 * 2];
    for (int i = 0; i < thedigest.length; i++) {
        chars[i * 2] = hexDigits[thedigest[i] >>> 4 & 0xf];
        chars[i * 2 + 1] = hexDigits[thedigest[i] & 0xf];
    return new String(chars);
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
return null;
Stringsha2(String input)
sha
MessageDigest mDigest = MessageDigest.getInstance("SHA-256");
byte[] result = mDigest.digest(input.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
    sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
return sb.toString();
Stringsha2(String password)
sha
try {
    MessageDigest mDigest = MessageDigest.getInstance("SHA-256");
    String salt = "random_salt_77"; 
    String passWithSalt = password + salt;
    byte[] passBytes = passWithSalt.getBytes();
    byte[] result = mDigest.digest(passBytes);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < result.length; i++) {
...