ios - Decrypt AES-256-CBC String (need IV, string/data format?) -


i've been going around in circles apple's cccrypto docs, frameworks , other answers , not making headway.

i think need figure out how iv encrypted string receive.

i receive json payload contains string. string encrypted in aes-256-cbc. (from laravel php instance think uses openssl). string itself, decrypted, json object.

i have pre-defined key.

the string receive looks like:

ejahdkawwkajashwlkwakajsne8ehahdhsiwkdkdhwniehhehellwhwlllllhshnnwhwhabwiiwhwhwh= 

(but lot longer).

i'm trying use answer here: issue using cccrypt (commoncrypt) in swift

but a) unsure if i'm converting string data , b) how iv (initialization vector) string receive.

using answer "success" when try pass nsjsonserailizer never got result (it fails) data out - think it's garbage.

edit:

i mis-understood original problem - receiving base64 encoded string needed decode json (which went fine). using linked answer , importing commoncrypto thought i'd able usable data not. @rob napier 's answer extremely helpful. think problem instance of laravel in question using openssl.

there no commonly used standard format aes encrypted data (there several "standard formats" they're not commonly used....) way know how data have encrypted @ documentation data format, or failing that, encrypting code itself.

in encryption formats, iv sent along data. in many common (insecure) formats, there hard-coded iv (sometimes 16 bytes of 0x00). if there's password, need find out how they've converted password key (there several ways this, good, horrible). in format, key derivation may include random "salt" need extract data. you'll need know if there hmac or similar authentication (which might stored @ beginning or end of data, , may include own salt).

there isn't way know without documentation sender. decently encrypted format going random noise, figuring out looking @ final message pretty hard.

if comes out of laravel's encrypt function, seems this code:

public function encrypt($value) {     $iv = mcrypt_create_iv($this->getivsize(), $this->getrandomizer());     $value = base64_encode($this->padandmcrypt($value, $iv));     // once have encrypted value go ahead base64_encode input     // vector , create mac encrypted value can verify     // authenticity. then, we'll json encode data in "payload" array.     $mac = $this->hash($iv = base64_encode($iv), $value);     return base64_encode(json_encode(compact('iv', 'value', 'mac'))); } 

if correct, should have been passed base64-encoded json 3 fields: iv (iv), ciphertext (value), , looks hmac encrypted using same key plaintext (mac). data you've given above doesn't json @ (even after base-64 decoding).

this assumes caller used encrypt function, though. there many, many ways encrypt, though, need know how actual server you're talking did it.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -