encryption - AES 256 加密解密,
问题描述
解密逻辑缺少某些内容,请您帮忙。输出未完全解密。
Java 加密逻辑:
public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, ShortBufferException, IllegalBlockSizeException, BadPaddingException {
try {
String in ="This is a text message";
byte[] input = in.toString().getBytes("utf-8");
String ENCRYPTION_KEY = "RW50ZXIgS2V5IEhlcmU=";
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] thedigest = md.digest(ENCRYPTION_KEY.getBytes("UTF-8"));
// SecretKeySpec skc = new SecretKeySpec(thedigest, "AES/ECB/PKCS5Padding");
SecretKeySpec skc = new SecretKeySpec(thedigest, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skc);
byte[] cipherText = new byte[cipher.getOutputSize(input.length)];
int ctLength = cipher.update(input, 0, input.length, cipherText, 0);
ctLength += cipher.doFinal(cipherText, ctLength);
// String query = Base64.encodeToString(cipherText, Base64.DEFAULT);
String query = new String(java.util.Base64.getEncoder().encode(cipherText));
System.out.println("query " + query);
// String query = new String(encode(cipherText), StandardCharsets.ISO_8859_1);
} catch(UnsupportedEncodingException e) { // TODO Auto-generated catch block
e.printStackTrace();
}
}
Nodejs解密逻辑:
let crypto = require('crypto');
var decipher = crypto.createDecipher('aes-256-ecb', "RW50ZXIgS2V5IEhlcmU=");
decipher.setAutoPadding(false);
console.log(decipher.update("EncyptedText", 'base64', 'utf8') + decipher.final('utf8'));
解决方案
推荐阅读
- python - 使用django rest框架的api设计理念
- select - 在 vue 上的选择中单击选项时如何获得价值?
- php - 从多个表中选择多行并使用 php while 循环打印所有行
- html - 仅使用 CSS 的方法来防止在句点字符之前的内联块之后中断,而句点周围没有标记
- java - 如何编辑重复初始化的标签?
- java - 如何在JNI层修改java类对象
- c# - Web 浏览器不会导航到链接
- c# - 配方成分转换
- terraform - terraform - 将变量值拆分为 2
- asp.net-core - 在 Asp.Net Core 中,如何从正文中获取多部分/表单数据?