Home:ALL Converter>AES 128 bit & AES 256 bit encryption decryption

AES 128 bit & AES 256 bit encryption decryption

Ask Time:2017-04-26T18:27:15         Author:RPrashant

Json Formatter

I am doing AES 128 bit encyption and decryption using following java code which works fine. For same key and data it gives me same output each time.

link1: http://aesencryption.net/#Java-aes-encryption-example

(final String strPssword = "dAtAbAsE98765432";)

For AES 256 bit encryption and decryption I found another java code. It gives me different output each time.

link2: AES-256 Password Based Encryption/Decryption in Java

My question is that, whether i need to wirte different code for AES 128 bit and AES 256 bit? Or are they same? only key size is different?

For 256 bit encryption only i need to change in first java code link

public boolean setKey(String sKey){
    arbtKey = Arrays.copyOf(arbtKey, 32); // use only first 256 bits
}

public static void main(String[] aryCmdArgs)
{
    final String sKey = "dAtAbAsE98765432dAtAbAsE98765432"; //256 bits
}

or i need to use a code given in link2?

Author:RPrashant,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/43631547/aes-128-bit-aes-256-bit-encryption-decryption
yy