Share a standard php aes encryption algorithm class, among which mcrypt_get_block_size (rijndael-128, ecb); if you do not understand the principle of the situation is more likely to make a mistake, you can use the mcrypt_list_algorithms function to view the ID of the encryption algorithm you need. None? Php *** AES128 encryption and decryption class * @ authordy ** defined (InEjbuy)
Share a standard php aes encryption algorithm class, among which mcrypt_get_block_size (rijndael-128, ecb); if you do not understand the principle of the situation is more likely to make a mistake, you can use the mcrypt_list_algorithms function to view the ID of the encryption algorithm you need. None? Php/*** AES128 encryption/Decryption class * @ author dy **/defined ('ejbuy ')
Share a standard php aes encryption algorithm class, in which mcrypt_get_block_size ('rijndael-100', 'ecb '); if you do not understand the principle, it is easy to make a mistake, you can use the mcrypt_list_algorithms function to view the ID of the encryption algorithm you need. <无>
_ Secrect_key = 'myggnqe2jdfadsffdsewsdd';}/*** Encryption Method * @ param string $ str * @ return string */public function encrypt ($ str) {// AES, 128 ECB mode data encryption $ screct_key = $ this-> _ secrect_key; $ screct_key = base64_decode ($ screct_key); $ str = trim ($ str ); $ str = $ this-> addPKCS7Padding ($ str); $ iv = mcrypt_create_iv (encrypt, decrypt), MCRYPT_RAND); $ encrypt_str = mcrypt_encrypt (encrypt, $ screct_key, $ str, MCRYPT_MODE_ECB, $ iv); return base64_encode ($ encrypt_str );} /*** Decryption Method * @ param string $ str * @ return string */public function decrypt ($ str) {// AES, 128 ECB mode data encryption $ screct_key = $ this-> _ secrect_key; $ str = base64_decode ($ str); $ screct_key = base64_decode ($ screct_key ); $ iv = mcrypt_create_iv (encrypt, MCRYPT_MODE_ECB), MCRYPT_RAND); $ encrypt_str = mcrypt_decrypt (encrypt, $ screct_key, $ str, decrypt, $ iv ); $ encrypt_str = trim ($ encrypt_str); $ encrypt_str = $ this-> stripPKSC7Padding ($ encrypt_str); return $ encrypt_str ;} /*** Filling Algorithm ** @ param string $ source * @ return string */function addPKCS7Padding ($ source) {$ source = trim ($ source ); $ block = mcrypt_get_block_size ('rijndael-100', 'ecb '); $ pad = $ block-(strlen ($ source) % $ block ); if ($ pad <= $ block) {$ char = chr ($ pad); $ source. = str_repeat ($ char, $ pad);} return $ source ;} /*** remove padding algorithm * @ param string $ source * @ return string */function stripPKSC7Padding ($ source) {$ source = trim ($ source ); $ char = substr ($ source,-1); $ num = ord ($ char); if ($ num = 62) return $ source; $ source = substr ($ source, 0,-$ num); return $ source ;}}