加密将Python脚本转换为PHP

时间:2019-07-02 15:40:02

标签: php python encryption-symmetric

我已经收到一个Python代码段,用于加密密码,需要使用标准PHP函数将其转换为PHP

这是蟒蛇

raw = pad(raw) #padding string with non-printable characters to a multiple of 16 characters
print(raw)        
iv = Random.new().read( AES.block_size ) #A 16 character length random ASCI value string        
print(iv)        
cipher = AES.new( self.key, AES.MODE_CBC, iv ) #encrypt padded data        
return base64.b64encode( iv + cipher.encrypt( raw ) )  #base64 encode IV string and then encrypted value

这是PHP尝试

define('AES_128_CBC', 'aes-128-cbc');
$encryption_key = "";
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(AES_128_CBC));
$data = "password";
echo "<p>Before encryption: $data\n";
$encrypted1 = openssl_encrypt($data, AES_128_CBC, $encryption_key, 0, $iv);
echo $encrypted = base64_encode($iv) . $encrypted1;

不确定Python加密函数是否映射到所使用的PHP函数

0 个答案:

没有答案