api接口数据如何加密
使用AES加密算法对api接口数据进行加密,具体方法以下:
<?php
//$key previously generated safely, ie: openssl_random_pseudo_bytes
$key='123456789';
$plaintext="hello world";
//$cipher = "aes⑴28-cbc";
$cipher = "AES⑴28-ECB";
if (in_array($cipher, openssl_get_cipher_methods()))
{
// $iv='1111111111111111';
$iv='';
$ciphertext = openssl_encrypt($plaintext, $cipher, $key, OPENSSL_RAW_DATA, $iv);
$ciphertext =base64_encode($ciphertext);
//store $cipher, $iv, and $tag for decryption later
$original_plaintext = openssl_decrypt(base64_decode($ciphertext), $cipher, $key, OPENSSL_RAW_DATA, $iv);
var_dump( $original_plaintext);
var_dump( $ciphertext);
}
本文来源:https://www.yuntue.com/post/59102.html | 云服务器网,转载请注明出处!