//使用公钥加密,私钥解密
$public_key = "-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA14VJBWSyVOI4Q4aV+Cvl
GX4Vb4wczPw0qQbGYAYzfuA7+RpO/X5DG7dFjdBMmb9cHvdWY8+uvKDVuHjbvCpm
3nSTgMbCLm/zDDTH8MUySSaxvm0tbdWm+L1Rinw5LZ+B1J9tHEXMwJZ2g5ZS4OZ0
4xlXx/4GWd9QBuV036er47J/cZ19WPgBDqQ4Mmm2X2na46NCeRenRBXLsaQhxvEe
5pX3WtguQtr+QrcekAmBoI1Xc0xhKDyXZ34rqZNvVCUNn11VzDcffanxlmTFFKDp
QCZLVf8gtSdcxxQQrOfStgLoyYbN1e2Spb/szfQHtbSZ1qHg1frhCvjgOmZ6gDi+
OQIDAQAB
-----END PUBLIC KEY-----";//公钥
$private_key = "-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDXhUkFZLJU4jhD
hpX4K+UZfhVvjBzM/DSpBsZgBjN+4Dv5Gk79fkMbt0WN0EyZv1we91Zjz668oNW4
eNu8KmbedJOAxsIub/MMNMfwxTJJJrG+bS1t1ab4vVGKfDktn4HUn20cRczAlnaD
llLg5nTjGVfH/gZZ31AG5XTfp6vjsn9xnX1Y+AEOpDgyabZfadrjo0J5F6dEFcux
pCHG8R7mlfda2C5C2v5Ctx6QCYGgjVdzTGEoPJdnfiupk29UJQ2fXVXMNx99qfGW
ZMUUoOlAJktV/yC1J1zHFBCs59K2AujJhs3V7ZKlv+zN9Ae1tJnWoeDV+uEK+OA6
ZnqAOL45AgMBAAECggEAEdjMsjCjf9n31MepVZK09wZ02fbdT7A24CRaewsoaoJB
FSCzl9RD1GC51sOABF9PTpUmxz8kdiRPbmY7s/pC6Hr41/odjGDi3IjmYa7CukIF
CALcdzLxD7oFrZUZ2whRZP0KuQOir/QFvmHNXShYV5H6reoANqMCan/HzNm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----END PRIVATE KEY-----";//私钥
$text ='我是待加密的内容';
//公钥加密,参数二$data为加密后的内容
$res = openssl_public_encrypt($text,$encrypt,$public_key);
if($res==false) echo '加密失败';
//私钥解密,参数一:待解密的数据
//参数二:解密后的明文内容
$res = openssl_private_decrypt($encrypt,$decrypt,$private_key);
if($res==false) echo '解密失败';
echo '解密后的明文数据:'.$decrypt
|