Dinash
Dinash

Reputation: 3047

Decrypt image using AES Algorithm with password

hi guys could any one tell me how i can decrypt a image with password using the AES Algorithm.The Image has been encrypted in the iphone with some password.

Thanks in advance

Edit #1 The thing is that the user will select some image from a iPhone app and encrypt it with user entered password and post it to server. And now what we need to do is to download the image from the server and decrypt with the same password and display the image to the user. And in iphone they have given the password with length 4 like 'test'. Hope you can understand better what i m trying to do.

In iPhone they have followed this link

Upvotes: 1

Views: 1574

Answers (2)

Barmaley
Barmaley

Reputation: 16363

To decrypt image you'd need to know 2 things:

  1. Key generation procedure details. Usually it's done using hash calculation based on supplied password. Sometimes password can be reinforced using so-called password salting. If so you'd need to know password salt. Basically:

    key=hash(password+salt)

  2. Even if you know key also you have to know ciphering mode (those mysterious ECB/CBC and so on). Basically operation mode means how encrypted blocks chained to each other.

Without those 2 parameters it's useless to decrypt - so "Use The Source Luke!"

Upvotes: 1

Yann Ramin
Yann Ramin

Reputation: 33197

Well, first you need to know the key which was derived from the password. Did they use PBKDF#2? How many rounds? AES doesn't have "passwords", it has keys.

Second, which mode was the image encrypted in? ECB? CBC? CTR? GCM?

If you have a byte[] of data, SecretKey of key, and byte[] of IV, and used CBC mode, you can use the following for the decryption:

cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); 
ciphertext = cipher.doFinal(imageByte);

Since there are a ton of unknowns here, I can't proffer the exact solution.

Upvotes: 1

Related Questions