弄了很久,还是不会用其他论坛的方法去代替这个功能,望大佬赐教。。。。。
[Java] 纯文本查看 复制代码
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public static String getEncryptString(String str) {
BASE64Encoder base64encoder = new BASE64Encoder();
try {
byte[] bytes = str.getBytes(CHARSETNAME);
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] doFinal = cipher.doFinal(bytes);
return base64encoder.encode(doFinal);
} catch (Exception e) {
// TODO: handle exception
throw new RuntimeException(e);
}
}
public static String getDecryptString(String str) {
BASE64Decoder base64decoder = new BASE64Decoder();
try {
byte[] bytes = base64decoder.decodeBuffer(str);
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] doFinal = cipher.doFinal(bytes);
return new String(doFinal, CHARSETNAME);
} catch (Exception e) {
// TODO: handle exception
throw new RuntimeException(e);
}
}
|