Skip to navigation
Example encryption what can be encrypted and decrypted by php and python
13.02.19
python: 1. install pycrypto pip install pycrypto 2. from Crypto.Cipher import AES import base64 s = "foobar" place_holder= '{' missing = 16 - (len(s) % 16) s += place_holder * missing aes = AES.new('1234567891234567', AES.MODE_CBC, '1234567891234567') c = aes.encrypt(s) aes2 = AES.new('1234567891234567', AES.MODE_CBC, '1234567891234567') d = aes2.decrypt(c).decode('utf-8').replace('{','') print(base64.b64encode(c).decode('utf-8')) print(d) php: $enc = "SeOLTcxi7AE9oYAYnD6UOg=="; $secret = "1234567891234567"; $iv = "1234567891234567"; $res = $this->decrypt_data(base64_decode($enc), $iv, $secret); var_dump($res); function decrypt_data($data, $iv, $key,$place_holder='{') { $cypher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); if(is_null($iv)): $ivlen = mcrypt_enc_get_iv_size($cypher); $iv = substr($data, 0, $ivlen); $data = substr($data, $ivlen); endif; if(mcrypt_generic_init($cypher, $key, $iv) != -1): $decrypted = mdecrypt_generic($cypher, $data); mcrypt_generic_deinit($cypher); mcrypt_module_close($cypher); return str_replace($place_holder,'',$decrypted); endif; return false; }
https://pypi.org/project/pycrypto/
Reply
Anonymous
Information Epoch 1732646219
Use lower case and keep it short.
Home
Notebook
Contact us