SHA encryption

package com.dc;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;  
import java.security.NoSuchAlgorithmException;  

/* ******************** Class description ********************
 * class       :  DcSHAUtil
 * @author     :  ncc
 * create time : 2017-12-19 10:36:08 am
 * @version    :  1.0  
 * description : SHA is a data encryption algorithm, which has been increasingly perfected by the development and improvement of encryption experts over the years.
 * is now recognized as one of the most secure hashing algorithms and is widely used. The idea of ​​the algorithm is to receive a piece of plaintext,
 * then convert it into a (usually smaller) ciphertext in an irreversible way,
 * It can also be simply understood as taking a string of input codes (called pre-mapping or information),
 * and convert them into a short-length, fixed-digit output sequence that is a hash value (also known as a message digest or message authentication code).
 * The hash function value can be said to be a kind of "fingerprint" or "digest" of the plaintext, so the digital signature of the hash value can be regarded as the digital signature of the plaintext.
 * @see        :                        
 * ************************************************/   
public class DcSHAUtil {  
      
    /* ********************************************
     * method name   : eccrypt
     * description : encrypted string
     * @return       : byte[]
     * @param : @param info
     * @param        : @return
     * @param        : @throws NoSuchAlgorithmException
     * modified      : ncc ,  2017-12-19
     * @see          :
     * ********************************************/      
    public byte[] eccrypt(String info) throws NoSuchAlgorithmException{  
        MessageDigest md5 = MessageDigest.getInstance("SHA");  
        byte[] srcBytes = info.getBytes();  
        //Update digest with srcBytes  
        md5.update(srcBytes);  
        //Complete the hash calculation and get the result  
        byte[] resultBytes = md5.digest();  
        return resultBytes;  
    }  
  
    /**
     * @param args
     * @throws NoSuchAlgorithmException  
     * @throws UnsupportedEncodingException
     */  
    public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException {  
        String msg = "Welcome to the home of the grass!";  
        DcSHAUtil sha = new DcSHAUtil();  
        byte[] resultBytes = sha.eccrypt(msg);  
        System.out.println("Plaintext is: " + msg);
        System.out.println("密文是:" + new String(resultBytes));  
    }  
}

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326442003&siteId=291194637