【发布时间】:2014-04-21 16:05:31
【问题描述】:
我已经对程序的每个步骤进行了很多测试,我得到了输出,但是当我测试 BASE64Encoder() 行时它不起作用,我完全卡住了,即使 Eclipse 在 BASE64Encoder() 行上没有显示任何错误,我想要你的帮助如何摆脱这个问题, 代码如下
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
}
【问题讨论】:
-
它对我有用,是的,我知道我不应该使用它。您是否收到表示异常的“未知错误”,如果有,该怎么办?还是你只得到一个空字符串?
-
我测试了每一行都能正常工作,但是当我想要字符串值 encStr 时,它对我不起作用 未知错误不输出,甚至代码@EJP 中没有显示异常问题
-
你不是很清楚。 “未知错误”是什么意思?你得到输出的“Pincode city:”部分吗?这可能根本不是 Base64 问题,只是 I/O 问题。
-
@EJP 当我通过删除 httpservletresponse 在桌面上运行该程序时,它正在工作和加密,但是当我在 google appengine 中部署它并提供它没有输出的字符串时
标签: java arrays jakarta-ee servlets servlet-3.0