Where to specify key and IV value when doing AES encryption/decryption in Android? -
i working on aes encryption , decryption in android. have audio file encrypted using aes/cbc. have key , iv (initialization vector).
i have read links. this
secretkeyspec skeyspec = new secretkeyspec(raw, "aes");
the secretkeyspec class used. should use key , iv values?
and need decrypt first 256 bytes data only. how can achieve this?
in code snippet, raw
key (as byte array):
secretkeyspec skeyspec = new secretkeyspec(raw, "aes"); // ^^^ key
of course, if have key hex string, you'll need convert bytes.
when encrypting, can either specify iv or let random 1 generated. if want specify yourself, use:
cipher cipher = cipher.getinstance("aes/cbc/pkcs5padding"); // adjust padding cipher.init(cipher.encrypt_mode, skeyspec, new ivparameterspec(...));
if want use automatic one, sure record 1 chosen calling
cipher.getiv();
for decryption, must specify iv , using ivparameterspec
, encryption.
and need decrypt first 256 bytes data only. how can achieve this?
consider using cipherinputstream
, read 256 bytes it.
Comments
Post a Comment