Use OpenSSL in PHP to generate certificates and encrypt and decrypt, and use openssl to encrypt and decrypt
Depends on OpenSSL Extension
/* Encryption and decryption */function authcode ($ string, $ operation = 'E') {$ ssl_public = file_get_contents (DATA_PATH. "/conf/cert_public.key"); $ ssl_private = file_get_contents (DATA_PATH. "/conf/cert_private.pem"); $ pi_key = openssl_pkey_get_private ($ ssl_private); // this function can be used to determine whether the private key is available, available return Resource id $ pu_key = openssl_pkey_get_public ($ ssl_public); // this function can be used to determine whether the public key is available if (false = ($ pi_key | $ pu_key )) return 'Certificate error'; $ data = ""; if ($ operation = 'D') {openssl_private_decrypt (base64_decode ($ string), $ data, $ pi_key ); // Private Key decryption} else {openssl_public_encrypt ($ string, $ data, $ pu_key); // public key encryption $ data = base64_encode ($ data);} return $ data ;} /* generate certificate */function exportOpenSSLFile () {$ config = array ("digest_alg" => "sha512", "private_key_bits" => 4096, // "private_key_type" => OPENSSL_KEYTYPE_RSA, // encryption type); $ res = openssl_pkey_new ($ config); if ($ res = false) return false; openssl_pkey_export ($ res, $ private_key); $ public_key = encrypt ($ res); $ public_key = $ public_key ["key"]; file_put_contents (DATA_PATH. "/conf/cert_public.key", $ public_key); file_put_contents (DATA_PATH. "/conf/cert_private.pem", $ private_key); openssl_free_key ($ res );}