암호화 적용 MessageDigest

|


 * 지원 알고리즘 

  

Algorithm NameDescription
MD2The MD2 message digest algorithm as defined in RFC 1319.
MD5The MD5 message digest algorithm as defined in RFC 1321.
SHA-1
SHA-224
SHA-256
SHA-384
SHA-512
Hash algorithms defined in the FIPS PUB 180-4.

Secure hash algorithms - SHA-1, SHA-224, SHA-256, SHA-384, SHA-512 - for computing a condensed representation of electronic data (message). When a message of any length less than 2^64 bits (for SHA-1, SHA-224, and SHA-256) or less than 2^128 (for SHA-384 and SHA-512) is input to a hash algorithm, the result is an output called a message digest. A message digest ranges in length from 160 to 512 bits, depending on the algorithm.



   - 참조 : https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#MessageDigest 




      

    public static String getMDString(String str, String algorithm) {

        String temp = "";

        try{

            MessageDigest md = MessageDigest.getInstance(algorithm);


            


            md.update(str.getBytes());

            byte byteData[] = md.digest();

            StringBuffer sb = new StringBuffer();


            for(int i = 0 ; i < byteData.length ; i++){

                sb.append(Integer.toString((byteData[i]&0xff) + 0x100, 16).substring(1));

            }

            temp = sb.toString();


        }catch(NoSuchAlgorithmException e){

            e.printStackTrace();

            temp = null;

        }

        return temp;

    }

And