加密后插入数据库

encode()参数是要加密的内容,会返回加密后的字符串

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.log4j.Logger;
import sun.misc.BASE64Encoder;
public class CodeUtils {
    private static Logger logger = LogManager.getLogger(LogManager.LOG_KEY_APP);
    private static MessageDigest MD5 = null;
        
    static {
        try {
            MD5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
            logger.debug(ex);
        }
    }
        
    public static String encode(String value) {
        String result = "";
        if (value == null) {
            return result;
        }
        BASE64Encoder baseEncoder = new BASE64Encoder();
        try {
            result = baseEncoder.encode(MD5.digest(value.getBytes("utf-8")));
        } catch (Exception ex) {
        }
        return result;
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案