开发者

How to encrypt/decrypt multiple strings in AES encryption?

I would like to know if I could encrypt two or more strings in AES encryption. Let's say, I want to encrypt username, password and nonce_value. Can I use the following code?

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

    System.out.println("Encrypted : " + encryptedData);
    System.out开发者_JAVA百科.println("Decrypted : " + decryptedData);
} catch (Throwable e) {
    e.printStackTrace();
}


Well does that work? Why not try that code and see? In theory you certainly can put multiple pieces of data together into one string and encrypt that string, though you'd want a better way of putting the data together. Your current code, with commas between username, password, and nonceInString won't compile, but if you can prevent, for instance, a colon existing in any of those strings, you could do something like:

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

And then when you decode simply split on the colon.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜