api接口数据怎么加密

1949idc 2年前 (2024-09-13) 阅读数 397 #智能运维

使用AES加密算法对api接口数据进行加密,具体方法如下:

//$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);

}

版权声明

本文内容由互联网用户自发贡献,该文观点仅代表作者本人
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

© 2010 首途云安 & 厦门硕顿信息技术有限公司 & 闽ICP备11016866号  增值电信业务经营许可证:B1-20203020 地址:福建厦门思明区嘉禾路297号1806
高新技术企业
软件产品证书
计算机软件著作权
ISO认证
国家3A企业