In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "php how to achieve aes encryption", in daily operation, I believe many people in php how to achieve aes encryption problems have doubts, small series consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "php how to achieve aes encryption" doubts helpful! Next, please follow the small series to learn together!
In PHP, you can use the "openssl_encrypt()" function to implement aes encryption, just need to set the encryption method in the parameter to "AES-128-ECB", the syntax is "openssl_decrypt(encrypted plaintext,'AES-128-ECB', encryption key, data format)".
Operating environment: Windows 10 system, PHP 7.1 version, Dell G3 computer.
How does PHP implement AES encryption?
In php we use openssl_encrypt for encryption and openssl_decrypt for decryption
One: openssl_encrypt method detailed explanation:
openssl_encrypt($data, $method, $key, $options = 0, $iv = "", &$tag = NULL, $aad = "", $tag_length = 16)
Parameters:
1.$ data: encrypted plaintext
2.$ method: encryption method: you can get which encryption methods are available through openssl_get_cipher_methods()
3.$ passwd: encryption key [password]
4.$ options: Data format options (optional)[options include: ]: 0, OPENSSL_RAW_DATA = 1, OPENSSL_ZERO_PADDING = 2, OPENSSL_NO_PADDING =3
5.$ iv: Secret initialization vector (optional), Note: If method is DES−ECB, iv does not need to be filled in
6.$ tag: authentication tag (optional) that is passed on when using AEAD cipher mode (GCM or CCM)
7.$ aad: Additional validation data. (Optional)
8.$ tag_length: Verify the tag length. In GCM mode, its range is 4 to 16(optional)
Second: openssl_decrypt method detailed explanation
openssl_decrypt($data, $method, $password, $options = 1, $iv = "", $tag = "", $aad = "")
Parameters:
1.$ data: Encrypted message to be decrypted.
2.$ method: decryption method: can be obtained through openssl_get_cipher_methods() which decryption methods
3.$ passwd: decryption key [password]
4.$ options: Data format options (optional)[options include: ] 0, OPENSSL_RAW_DATA = 1, OPENSSL_ZERO_PADDING = 2, OPENSSL_NO_PADDING =3
5.$ iv: Secret initialization vector (optional), Note: If method is DES−ECB, iv does not need to be filled in
6.$ tag: Authentication tag in AEAD password mode (optional)
7.$ aad: Additional validation data. (Optional)
III: Implementation of AES encryption and decryption
1: AES encryption
//string to encrypt $data = 'test';//key $key = ' 123456';//encrypted data 'AES-128-ECB' can be obtained via openssl_get_cipher_methods()$encrypt = openssl_encrypt($data, 'AES-128-ECB',$key, 0);echo (($encrypt));
2:AES decryption
//decrypt string $encrypt = '***';//key $key = '123456';//decrypt data $decrypt = openssl_decrypt($encrypt, 'AES-128-ECB',$key, 0);echo $decrypt;
According to the above, AES encryption and decryption functions can be realized.
At this point, on the "php how to achieve aes encryption" learning is over, I hope to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.