Hi Ulf
Actually first time i'm trying to implement AES-128/AES-256.I don't have much idea on it.
Following sample code i'm using which is working fine for AES-128 for
testing purpose.If following will work for AES-256 then only i can go for real implement.
Please Help me out to resolve this issue.
package com.mytestapp;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
public class EncryptTest {
public EncryptTest()
{
}
public static void main(
String[] args) throws Exception
{
KeyGenerator keygen = KeyGenerator.getInstance("AES");
// keygen.init(128); //this works fine!
keygen.init(256); //this breaks!
SecretKey aesKey = keygen.generateKey();
Cipher aesCipher;
aesCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
aesCipher.init(Cipher.ENCRYPT_MODE, aesKey);
byte[] clearText = "This is an example!".getBytes();
System.out.println("ClearText: "+new String(clearText));
byte[] cipherText = aesCipher.doFinal(clearText);
System.out.println("CipherText: "+new String(cipherText));
aesCipher.init(Cipher.DECRYPT_MODE, aesKey);
byte[] clearTextDecrypt = aesCipher.doFinal(cipherText);
System.out.println("DecryptedText: " + new String(clearTextDecrypt));
boolean equalText = Arrays.equals(clearText, clearTextDecrypt);
if (equalText)
{
System.out.println("String was recovered!");
}
else
{
System.out.println("String was NOT recovered!! Booooooo....");
}
}
}