api接口數(shù)據(jù)怎么加密

九三
457
2021-03-05 12:48:22

api接口數(shù)據(jù)怎么加密

使用AES加密算法對(duì)api接口數(shù)據(jù)進(jìn)行加密,具體方法如下:

//$key previously generated safely, ie: openssl_random_pseudo_bytes

$key='123456789';

$plaintext="hello world";

//$cipher = "aes-128-cbc";

$cipher = "AES-128-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);

}

0