php PKCS5Padding
时间: 2023-10-13 14:42:25 浏览: 116
AES_ECB_PKCS5Padding.php
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.
阅读全文