Pkcs7Encoder使用AES-128-ECB算法加密
代码:<?php
namespace addons\carplate\library;
class Pkcs7Encoder
{
// 加密函数
public function aes_encrypt($plaintext, $key) {
// 使用AES-128-ECB算法加密
$cipher = "AES-128-ECB";
// 对明文进行填充
$plaintext = $this->pkcs7_pad($plaintext, 16);
// 执行加密
$ciphertext = openssl_encrypt($plaintext, $cipher, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
return base64_encode($ciphertext);
}
// 填充函数
public function pkcs7_pad($data, $blocksize) {
$padding = $blocksize - (strlen($data) % $blocksize);
return $data . str_repeat(chr($padding), $padding);
}
}
页:
[1]