将字节数组转换为字符串的问题
解密方法未能将接收的字节数组转换为字符串
public String decryptData(String data, SecretKeySpec key) throws Exception{
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decodedValue = Base64.decode(data, Base64.DEFAULT);
byte[] decValue = cipher.doFinal(decodedValue);
String outputData = new String(decValue, StandardCharsets.US_ASCII);
Log.d("Log byte:", decodedValue.toString());
Log.d("Log byte:", decValue.toString());
Log.d("Log str:", outputData);
}
输出日志:
D/Log byte:: [B@4b0fd32
D/Log byte:: [B@32d3a83
D/Log str::
cipher.dofinal()返回一个空数组,我认为这就是为什么我得到一个空字符串值
The decryption method fails to convert the received byte array into a string
public String decryptData(String data, SecretKeySpec key) throws Exception{
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decodedValue = Base64.decode(data, Base64.DEFAULT);
byte[] decValue = cipher.doFinal(decodedValue);
String outputData = new String(decValue, StandardCharsets.US_ASCII);
Log.d("Log byte:", decodedValue.toString());
Log.d("Log byte:", decValue.toString());
Log.d("Log str:", outputData);
}
Output logs:
D/Log byte:: [B@4b0fd32
D/Log byte:: [B@32d3a83
D/Log str::
cipher.doFinal() returns an empty array, i think that's why I'm getting an empty String value
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用此方法使用AES方法进行解密。
I am using this method for decryption with AES method.