<? Php $ Private_key = '----- begin rsa private key ----- MIICXQIBAAKBgQC3 // sR2tXw0wrC2DySx8vNGlqt3Y7ldU9 + LBLI6e1KS5lfc5jl Bytes/ Gqx7/IRia3zQfxGv/qEkyGOx + XALVoOlZqDwh76o2n1vP1D + tD3amHsK7QIDAQAB AoGBAKH14bMitESqD4PYwODWmy7rrrvyFPEnJJTECLjvKB7IkrVxVDkp1XiJnGKH 2h5syHQ5qslPSGYJ1M/XkDnGINwaLVHVD3BoKKgKg1bZn7ao5pXT + herqxaVwWs6 Ga63yVSIC8jcODxiuvxJnUMQRLaqoF6aUb/2VWc2T5MDmxLhAkEA3pwGpvXgLiWL 3366qlyzlrlrbfrurn4cyl4uyaakokkavzly04glle8ycgoc2dzl4eil4l/+ x/gaq DeJU/cHLRQJBANOZY0mEoVkwhU4bScSdnfM6usQowYBEwHYYh/OTv1a3SqcCE1f + Bytes Oiq + Y8SgCCs73qixrU1YpJy9yKA/meG9smsl4Oh9IOIGI + zUygh9YdSmEq0CQQC2 4G3IP2G3lNDRdZIm5NZ7PfnmyRabxk/UgVUWdk47IwTZHFkdhxKfC8QepUhBsAHL Bytes YI9lblCsyfpl25l7l5zmJrAHn45zAiOoBrWqpM5edu7c ----- End rsa private key -----'; $ Public_key = '----- begin public key ----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3 // sR2tXw0wrC2DySx8vNGlqt 3Y7ldU9 + LBLI6e1KS5lfc5jlTGF7KBTSkCHBM3ouEHWqp1ZJ85iJe59aF5gIB2kl Bd6h4wrbbHA2XE1sq21ykja/Gqx7/IRia3zQfxGv/qEkyGOx + XALVoOlZqDwh76o 2n1vP1D + tD3amHsK7QIDAQAB ----- End public key -----'; // Echo $ private_key; $ Pi_key = openssl_pkey_get_private ($ private_key); // this function can be used to determine whether the private key is available. Resource id can be returned. $ Pu_key = openssl_pkey_get_public ($ public_key); // this function can be used to determine whether the public key is available. Print_r ($ pi_key); echo "\ n "; Print_r ($ pu_key); echo "\ n "; $ Data = "aassssasssddd"; // raw data $ Encrypted = ""; $ Decrypted = ""; Echo "source data:", $ data, "\ n "; Echo "private key encrypt: \ n "; Openssl_private_encrypt ($ data, $ encrypted, $ pi_key); // Private Key Encryption $ Encrypted = base64_encode ($ encrypted); // The encrypted content usually contains special characters. If you need to encode and convert the content, pay attention to whether base64 encoding is url-safe during url transmission between networks. Echo $ encrypted, "\ n "; Echo "public key decrypt: \ n "; Openssl_public_decrypt (base64_decode ($ encrypted), $ decrypted, $ pu_key); // the private key-encrypted content can be decrypted using the public key. Echo $ decrypted, "\ n "; Echo "--------------------------------------- \ n "; Echo "public key encrypt: \ n "; Openssl_public_encrypt ($ data, $ encrypted, $ pu_key); // public key encryption $ Encrypted = base64_encode ($ encrypted ); Echo $ encrypted, "\ n "; Echo "private key decrypt: \ n "; Openssl_private_decrypt (base64_decode ($ encrypted), $ decrypted, $ pi_key); // Private Key decryption Echo $ decrypted, "\ n "; |