java8以上版本已弃用的sun.misc.BASE64Decoder的代替用法
弄了很久,还是不会用其他论坛的方法去代替这个功能,望大佬赐教。。。。。{:1_937:}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);
}
}
用hutool吧,别造轮子了 <dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.4.6</version>
</dependency> java.util.Base64.Decoder和java.util.Base64.Encoder <dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.14</version>
</dependency>
这个也不错
页:
[1]