gpt4 book ai didi

java - 如何在 AES 加密中加密/解密多个字符串?

转载 作者:行者123 更新时间:2023-11-30 11:59:05 24 4
gpt4 key购买 nike

我想知道我是否可以在 AES 加密中加密两个或多个字符串。比方说,我想加密用户名、密码和 nonce_value。我可以使用以下代码吗?

try {
String codeWord = username, password, nonceInString;
String encryptedData = aseEncryptDecrypt.encrypt(codeWord);
String decryptedData = aseEncryptDecrypt.decrypt(encryptedData);

System.out.println("Encrypted : " + encryptedData);
System.out.println("Decrypted : " + decryptedData);
} catch (Throwable e) {
e.printStackTrace();
}

最佳答案

那行得通吗?为什么不试试那个代码看看呢?从理论上讲,您当然可以将多条数据放在一个字符串中并加密该字符串,尽管您需要一种更好的方法将数据放在一起。您当前的代码(在用户名、密码和 nonceInString 之间使用逗号)将无法编译,但如果您可以防止冒号存在于任何这些字符串中,您可以执行以下操作:

String codeWord = username+":"+password+":"+nonceInString;

然后当您解码时,只需在冒号处拆分即可。

关于java - 如何在 AES 加密中加密/解密多个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2734310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com