PHP code example of xj / php-rsa
1. Go to this page and download the library: Download xj/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/ */
xj / php-rsa example snippets
use xj\phprsa\RsaPrivate;
use xj\phprsa\RsaPublic;
$privateKey = <<<EOF
-----BEGIN RSA PRIVATE KEY-----
......................................
-----END RSA PRIVATE KEY-----
EOF;
$publicKey = <<<EOF
-----BEGIN PUBLIC KEY-----
......................................
-----END PUBLIC KEY-----
EOF;
$str = 'abcdefg';
//private encrypt -> public decrypt
$privateEncryptString = RsaPrivate::model($privateKey)->encrypt($str);
$publicDecryptString = RsaPublic::model($publicKey)->decrypt($privateEncryptString);
var_dump('private', $str, $privateEncryptString, $publicDecryptString);
//public encrypt -> private decrypt
$publicEncryptString = RsaPublic::model($publicKey)->encrypt($str);
$privateDecryptString = RsaPrivate::model($privateKey)->decrypt($publicEncryptString);
var_dump('public', $str, $publicEncryptString, $privateDecryptString);
json
""xj/php-rsa": "*"
},