【问题标题】:AES encryption base64().encodetoString unidentified by java netbeanjava netbean 无法识别的 AES 加密 base64().encodetoString
【发布时间】:2014-12-27 23:35:08
【问题描述】:

我目前正在研究此处的 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+enter on encodeAsString) 检查时,错误是

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

【问题讨论】:

    标签: java base64 aes


    【解决方案1】:

    尝试使用 org.apache.commons.codec.binary.Base64 而不是 Base64 的过时 sun 导入。另请参阅Java AES encryption and decryption(不,我不是否决这个问题的人)

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-12-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多