Decrypting PHP aes encryption in javascript -
i've been programming years now, never had encryption/decryption.
so i've got following php:
function base64_url_decode($input) { return base64_decode(strtr($input, '-_,', '+/=')); } function aesdecrypt($phrase, $user_key){ $key = pack('h*', $user_key); $ciphertext_dec = base64_url_decode($phrase); # may remove 00h valued characters end of plain text $plaintext_dec = mcrypt_decrypt(mcrypt_rijndael_128, $key, $ciphertext_dec, mcrypt_mode_ecb); return $plaintext_dec; } echo aesdecrypt( "-gzmiqhjynzw0fxtr6qolrypnlgcscbfgznmzga35tydoznwskwdxvietqwjhjigcydvvkb0lbkutx-txxhniqn680mziz8lg7hntmgprxm,", "2dd9bb29d2e25c18bdc12d7b75f6f5d0ef3d99ef310a0319e2796bb30278b24c557f78b6c958faa55d70ce081f2607a0e62b9fa01e2483f9a75b032b7fd9678c" );
the output of
1kyjjuajo8bilst5cvcsqygld_dqx-fjuihkefzfjouii7nx29ietz8qwtvih6yx5ui,
i've created js fiddle simulate have in javascript: http://jsfiddle.net/ndt3p/3/ (please scroll down line 545 since i've pasted in libraries using).
relevant javascript code:
var user_key = "2dd9bb29d2e25c18bdc12d7b75f6f5d0ef3d99ef310a0319e2796bb30278b24c557f78b6c958faa55d70ce081f2607a0e62b9fa01e2483f9a75b032b7fd9678c"; user_key = pack('h*', user_key); console.log(user_key); // same php functions var decrypted_wallet = "-gzmiqhjynzw0fxtr6qolrypnlgcscbfgznmzga35tydoznwskwdxvietqwjhjigcydvvkb0lbkutx-txxhniqn680mziz8lg7hntmgprxm," decrypted_wallet = base64.decode(strtr(decrypted_wallet, '-_,', '+/=')); console.log(decrypted_wallet); //same php function var decrypted = cryptojs.aes.decrypt(user_key,decrypted_wallet,{ mode: cryptojs.mode.ecb }); console.log(decrypted.tostring(cryptojs.enc.utf8)); // empty string
anyone point in right direction?
Comments
Post a Comment