PHP code example of niklaslu / php-rsa
1. Go to this page and download the library: Download niklaslu/php-rsa library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
niklaslu / php-rsa example snippets
= new \niklaslu\Rsa();
$publicKey = $Rsa->getPublicKeyStr();
echo $publicKey;
echo "<br>";
$pravateKey = $Rsa->getPrivateKeyStr();
echo $pravateKey;
echo "<br>";
$data = 'data1';
// 通过私钥加密
$enc = $Rsa->encryptByPrivate($data);
echo $enc;
echo "<br>";
// 通过公钥解密
$dec = $Rsa->decryptByPublic($enc);
echo $dec;
echo "<br>";
$data = 'data2';
// 通过公钥加密
$enc = $Rsa->encryptByPublic($data);
echo $enc;
echo "<br>";
// 通过私钥解密
$dec = $Rsa->decryptByPrivate($enc);
echo $dec;
echo "<br>";