AES加密base64()。由java netbean识别的encodetoString

时间:2014-01-29 01:55:35

标签: java base64 aes

我目前正在开发AES加密256位功能:

http://deveshsharma.info/2012/10/09/256-bit-aes-password-based-encryption-in-java

我现在要做的是查看上面代码的输出。但是在导入后,NetBean无法读取encodeAsString

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
...
byte[] encryptedTextBytes = cipher.doFinal(plainText.getBytes("UTF-8"));
return new     Base64().encodeAsString(encryptedTextBytes);

当我检查时(alt +输入encodeAsString),错误是

  

“找不到符号.Base64是内部专有API,可能是   在将来的版本中删除“

3 个答案:

答案 0 :(得分:2)

尝试使用org.apache.commons.codec.binary.Base64而不是Base64的过时sun导入。另见Java AES encryption and decryption(不,我不是那个投票问题的人)

答案 1 :(得分:2)

民间我意识到我没有为base64提供合适的jar。 对于与我有同样问题的人,请在http://commons.apache.org/proper/commons-codec/download_codec.cgi下载commons-codec-1.9-bin.zip以运行给定的代码。

答案 2 :(得分:2)

Java 8在 java.util.Base64 包中有一个Base64编码。它实际上是表现最好的人之一:performance comparisons of various encoders for the java platform

尽量不要在sun包下使用实现:例如com.sun.org.apache.xerces ....它们不受支持且速度慢得多。