/**
成都创新互联是一家朝气蓬勃的网站建设公司。公司专注于为企业提供信息化建设解决方案。从事网站开发,网站制作,网站设计,网站模板,微信公众号开发,软件开发,微信平台小程序开发,十余年建站对成都木托盘等多个方面,拥有多年的网站推广经验。
* ECB模式的des加密,以base64的编码输出
* @param message
* @param key
* @return
* @throws Exception
*/
public static String desEncrypt(String message, String key)throws Exception{
// DES/ECB CBC CFB OFB /PKCS5Padding NoPadding 加密/模式/填充
Cipher cipher = Cipher.getInstance("DES");//默认就是 DES/ECB/PKCS5Padding
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
cipher.init(1, secretKey);
return new BASE64Encoder().encode(cipher.doFinal(message.getBytes("UTF-8")));
}
/**
* ECB模式的des解密
* @param message
* @param key
* @return
* @throws Exception
*/
public static String desDecrypt(String message, String key)throws Exception{
Cipher 激配cipher = Cipher.getInstance("DES");
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
羡春 SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
cipher.init(2, secretKey);
return new String(cipher.doFinal(Base64.decode(message)), "UTF-8");
}
你自己写main方明派指法测试一下,应该是没问题的