Reputation: 17
I have tried a lot tested each step of my program, i get output but when i am testing BASE64Encoder() line it is not working,i stuck completely even eclipse not showing any error on BASE64Encoder() line ,I want your help how to get rid of this problem , code is given below
private void findMeaning(HttpServletResponse resp,String plainText) throws NoSuchAlgorithmException,
InvalidKeySpecException,
NoSuchPaddingException,
InvalidKeyException,
InvalidAlgorithmParameterException,
UnsupportedEncodingException,
IllegalBlockSizeException,
BadPaddingException,
IOException{
String text = plainText;
String key="ezeon8547";
KeySpec keySpec = new PBEKeySpec(key.toCharArray(), salt, iterationCount);//working
SecretKey key1 = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec); //working
// Prepare the parameter to the ciphers
AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);
ecipher = Cipher.getInstance(key1.getAlgorithm());//working
ecipher.init(Cipher.ENCRYPT_MODE, key1, paramSpec);//working
String charSet="UTF-8";
byte[] in = text.getBytes(charSet);//working
byte[] out = ecipher.doFinal(in);//working
String encStr=new sun.misc.BASE64Encoder().encode(out);//unknown error
sendResponse(resp, "Pincode city:" +encStr);//not get output
}
Upvotes: 0
Views: 125
Reputation: 93988
The solution is probably solved by not using any of the Sun classes. The Sun classes (i.e those with sun.*
package names distributed with the JRE) are not part of the Java API and should not be used. Use either Guava, Apache Commons Codec or Bouncy Castle lightweight API to perform the decoding.
For example, use org.apache.commons.codec.binary.Base64.decodeBase64(String)
.
If you want to stick to the normal Java API, use either java.util.Base64
(Java 8 onwards) or use up javax.xml.bind.DatatypeConverter
according to the answers of this question.
Upvotes: 2