-2

I am currently working on an AES encryption 256 bit function found here:

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

What I am trying to do now is to see the output of the code above. But NetBean can't read encodeAsString after I import it.

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

When I check with (alt+enter on encodeAsString), the error is

"cannot find symbol .. Base64 is internal proprietary API and may be removed in a future release"

Leigh
  • 28,765
  • 10
  • 55
  • 103
Learner
  • 101
  • 3
  • 15

3 Answers3

2

Try using org.apache.commons.codec.binary.Base64 instead of the obsolete sun import for Base64. See also Java AES encryption and decryption (and no I'm not the one who voted the question down)

Community
  • 1
  • 1
Teresa Carrigan
  • 668
  • 8
  • 14
2

Folk i realize i did not have the right jar for the base64. for folk who have the same problem as me please download commons-codec-1.9-bin.zip at http://commons.apache.org/proper/commons-codec/download_codec.cgi to able run the given code.

Learner
  • 101
  • 3
  • 15
2

Java 8 has a Base64 encode in package java.util.Base64. It is actually one of the better performers: performance comparisons of various encoders for the java platform

try not to use the implementation under the sun packages: e.g. com.sun.org.apache.xerces.... they are not supported and much slower.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Matthew Payne
  • 2,996
  • 2
  • 19
  • 15