Java SHA shaPsw(String inputText)

Here you can find the source of shaPsw(String inputText)

Description

sha Psw

License

Open Source License

Declaration

public static String shaPsw(String inputText) 

Method Source Code


//package com.java2s;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {

    public static String shaPsw(String inputText) {
        return encrypt(inputText, "sha-1");
    }//from  ww w.j  av a  2  s.co m

    private static String encrypt(String inputText, String algorithmName) {
        if (algorithmName == null || "".equals(algorithmName.trim())) {
            algorithmName = "md5";
        }
        String encryptText = null;
        try {
            MessageDigest m = MessageDigest.getInstance(algorithmName);
            m.update(inputText.getBytes("UTF8"));
            byte s[] = m.digest();
            m.digest(inputText.getBytes("UTF8"));
            return hex(s);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return encryptText;
    }

    private static String hex(byte[] arr) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr.length; ++i) {
            sb.append(Integer.toHexString((arr[i] & 0xFF) | 0x100).substring(1, 3));
        }
        return sb.toString();
    }
}

Related

  1. sha5Encode(byte[] content)
  2. SHA_1(byte[] input)
  3. shaFile(String paramString)
  4. SHAHash(byte[] input)
  5. shaHash(String message)
  6. SHAsum(byte[] convertme)
  7. SHAsum(byte[] convertme, boolean prefix, boolean uppercase)
  8. SHAsum(byte[] input)