views:

81

answers:

1

hello again everyone,

i would like to know if i could encrypt two or more strings in AES encryption. let 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.println("Decrypted : " + decryptedData);

}catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); }

thanks in advance. your suggestions and guidance will be very helpful for me.

A: 

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.

dimo414
hi dimo, thanks for your reply. yeah, i typed wrongly. the correct code was `String codeWord = username + password + nonceInString;` it works for both encryption and decryption.umm.. how do i drcrypted back to get the individual value?
sebby_zml
Well that's what I'm suggesting with doing something like delineating the values by colons, then you can use String.split() to get the parts again.http://java.sun.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String)
dimo414
thank you. it is solved. =)
sebby_zml
Glad I could help!
dimo414