试图将加密的数据从laravel php8应用程序发送到sage pay或opayo。
我不知道如何使用PHP8中的PKCS#5填充在CBC模式下执行AES (块大小为128位)。
Openssl似乎只让我们填充PKCS#7和旧的PHP示例和方法都依赖于弃用/删除的函数。
$cryptFieldString = http_build_query($cryptFields);
$encodedCrypt = openssl_encrypt($cryptFieldString, 'aes-128-cbc', $key, 0, $key);
$crypt = '@'.strtoupper(bin2hex($encodedCrypt));$encodedCrypt变量将始终返回PKCS#7或原始数据。
提前感谢
发布于 2021-11-11 09:53:18
PKCS#5填充只是在bin2hex和openssl_encrypt的组合中添加的,你不需要使用任何其他函数。但是,您必须检查编码是否支持,如下所示
if( in_array( 'AES-128-CBC', openssl_get_cipher_methods() ) ) {
$cipher_method = 'AES-128-CBC';
}
if( in_array( 'aes-128-cbc', openssl_get_cipher_methods() ) ) {
$cipher_method = 'aes-128-cbc';
}因此您可以使用bin2hex( openssl_encrypt( $input, $cipher_method, $securekey, OPENSSL_RAW_DATA, $securekey ) )
https://stackoverflow.com/questions/69122397
复制相似问题