加密后插入数据库
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; } }