php PKCS5Padding
时间: 2023-10-13 08:42:25 浏览: 47
PKCS5Padding is a padding scheme commonly used in cryptographic algorithms, including symmetric encryption algorithms. However, it is not directly applicable to PHP. In PHP, you can use the `openssl_encrypt` function to perform symmetric encryption, such as AES, and specify the padding scheme through the `options` parameter.
Here's an example of using PKCS5Padding with AES encryption in PHP:
```php
function encrypt($data, $key, $iv) {
$cipher = "aes-128-cbc";
$options = OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING;
$encrypted = openssl_encrypt($data, $cipher, $key, $options, $iv);
return $encrypted;
}
function decrypt($data, $key, $iv) {
$cipher = "aes-128-cbc";
$options = OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING;
$decrypted = openssl_decrypt($data, $cipher, $key, $options, $iv);
return $decrypted;
}
$key = "YourSecretKey";
$iv = "YourInitializationVector";
$data = "Hello, world!";
$encryptedData = encrypt($data, $key, $iv);
$decryptedData = decrypt($encryptedData, $key, $iv);
echo "Encrypted: " . base64_encode($encryptedData) . "\n";
echo "Decrypted: " . $decryptedData . "\n";
```
Remember to replace "YourSecretKey" and "YourInitializationVector" with your own values.
相关推荐
![php](https://img-home.csdnimg.cn/images/20210720083646.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![php](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)