Ciorna
Ciorna
// Criptare AES
SecretKeySpec myKey = new SecretKeySpec(keyBytes, "AES");
Cipher myAES = Cipher.getInstance("AES/CBC/PKCS5Padding");
// Key myKey;
myAES.init(Cipher.ENCRYPT_MODE, myKey, new IvParameterSpec(new byte[16]));
// // extra thingy added by us !
String plain = "acasaecelmaibine";
// initialize plaintext - modified by us !
byte[] plaintext = plain.getBytes();
//initialize ciphertext - we modified this, because we introduced
"AES/CBC/PKCS5Padding"
byte[] ciphertext = new byte[32];
int cLength = myAES.update(plaintext, 0, plaintext.length, ciphertext, 0);
myAES.doFinal(ciphertext, cLength);
System.out.println("plaintext: " + new
BigInteger(1,plaintext).toString(16));
System.out.println("ciphertext: " + new
BigInteger(1,ciphertext).toString(16));
myAES.init(Cipher.DECRYPT_MODE, myKey, new IvParameterSpec(new byte[16]));
byte[] dec_plaintext = new byte[16];
cLength = myAES.update(ciphertext, 0, ciphertext.length, dec_plaintext, 0);
cLength += myAES.doFinal(dec_plaintext, cLength);
System.out.println("decrypted: " + new
BigInteger(1,dec_plaintext).toString(16));