Andriod 的 DES 加密
1主要代码
关于 des 的导包 问题 要导 安卓本身的 64 位包 假设找com.sun.....可能会发生foundclass异常
String key;
public DES(String key)
{
this.key =key;
}
public String encrypt(String str) {
byte[] enc = null;
try {
enc = desEncrypt(str, key);
}
catch (Exception ex) {
}
// return new com.e.text.BASE64Encoder().encode(enc);
// return new BASE64Encoder().encode(enc);
return new String (Base64.encode( enc, Base64.DEFAULT));
}
public static byte[] desEncrypt(String message, String key) throws Exception {
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8"));
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
return cipher.doFinal(message.getBytes("UTF-8"));
}
附 demo
http://download.csdn.net/detail/wangchunshun/8180345