niklaslu/php-rsa

php rsa加密解密

1.0.0 2017-04-20 06:10 UTC

This package is not auto-updated.

Last update: 2024-04-24 12:55:08 UTC


README

php rsa 加密解密类

使用示例 demo.php

<?php

require_once 'vendor/autoload.php';

$Rsa = 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>";