I am working on AES encryption and decryption in android. I have an Audio file which is encrypted using AES/CBC. I have the key and IV (initialization vector).
I have read some links. From this
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
The SecretkeySpec class used. Where should I use my key and IV values?
And I need to decrypt only first 256 bytes data only. How can I achieve this?
In your code snippet,
raw
is your key (as a byte array):Of course, if you have your key as a hex string, you'll need to convert it to bytes.
When encrypting, you can either specify an IV yourself or let a random one be generated. If you want to specify yourself, use:
if you want to use an automatic one, be sure to record which one was chosen by calling
For decryption, you must specify the IV and you do so using an
IvParameterSpec
, just like with encryption.Consider using a
CipherInputStream
and read only 256 bytes from it.