PHP代码:
<?php
$privateKeyFilePath = '-----BEGIN RSA PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJDArkki2k3+xhze
v5emztqFtUhOzVlSveQ5dOLC4nNlLg8r81I9xBaXB7m4rb6lVjLgUuAXKUJ8y7yH
eE02s695cR/ZD0fierrMKMkmTFZIqOVYchn15N8EPz5e8WFirtP+Kaol4jDOaLCP
CSIs8QrQE6kEC7WDBi2/0mCkNI7PAgMBAAECgYB0oZuMODXXZDGyb1PGWFQRRGyl
n0Db+MwiCJ2CXG5jdiHffZUnLbdCUFycKw5rLwK+KXr9LgxDkxQBitHGvQ2XXO8w
v/2MQT658Eb49iQxZfuuhFFN8YIJZ4oFVyQQWXyCRAopyi/B0Eh6LTTTPjC/udPX
MoC0vSZl93Db8KPdyQJBANLPOnmyQmua6za/fFhWl13lsa+Ko73LhGi6dpiBjdpw
j0hp6NV/7yGCvHJFUr0hc9p5/lVJHkeAS/QtxF1IqXMCQQCvyGVL5uXj4didkO50
4HDgpPAgdROCZ6KrrNIf+RnCDn9Ffa1oA+n5cnno4trZVAYLU4yzZ63tQ/Z81ZfS
+h41AkBPXuyyUzaE0zBKTbBghkG5fbj30egyloTE9aefZe/l1clsx0t9zwxW/qU7
FPTA9u5qzNHAhKYc36Y5Sl4LjUcXAkBX50mopEXQKI+Pc/ubHOW1oSWnxYRFERhK
63iEnqgf3+oLUSbXPiXSJUoLiO5SAe+n2FcjHDTg0ry/fnyW95cFAkEAyllpaHTu
V5FPt6J5wZcEUbZoZsxYGmfUEg6HUE8BbGgRWwaem94p668ILaqGtxGKLKgbWoTM
Z8ZM+5cR/+C+yA==
-----END RSA PRIVATE KEY-----';
/**
* 公钥文件的路径
*/
$publicKeyFilePath = '-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCQwK5JItpN/sYc3r+Xps7ahbVI
Ts1ZUr3kOXTiwuJzZS4PK/NSPcQWlwe5uK2+pVYy4FLgFylCfMu8h3hNNrOveXEf
2Q9H4nq6zCjJJkxWSKjlWHIZ9eTfBD8+XvFhYq7T/imqJeIwzmiwjwkiLPEK0BOp
BAu1gwYtv9JgpDSOzwIDAQAB
-----END PUBLIC KEY-----';
extension_loaded('openssl') or die('php需要openssl扩展支持');
/**
* 生成Resource类型的密钥,如果密钥文件内容被破坏,openssl_pkey_get_private函数返回false
*/
$privateKey =openssl_pkey_get_private($privateKeyFilePath);
/**
* 生成Resource类型的公钥,如果公钥文件内容被破坏,openssl_pkey_get_public函数返回false
*/
$publicKey =openssl_pkey_get_public($publicKeyFilePath);
($privateKey) or die('密钥不可用');
($publicKey) or die('公钥不可用');
/**
* 原数据
*/
$originalData = 'test';
/**
* 加密以后的数据,用于在网路上传输
*/
$encryptData = '