xj/yii2-rsa

yii2-rsa

Installs: 3 772

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 2

Forks: 4

Open Issues: 1

Type:yii2-extension

1.0.1 2020-02-21 03:46 UTC

This package is auto-updated.

Last update: 2024-11-21 19:54:45 UTC


README

composer.json

"require": {
    "xj/yii2-rsa": "*"
},

Rsa

openssl genrsa -out rsa_private_key.pem 2048
openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem

example:

use xj\rsa\RsaPrivate;
use xj\rsa\RsaPublic;

//init
$privateKey = '@common/config/key-private.php';
$publicKey = '@common/config/key-public.php';
$str = 'yii2-rsa';

//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);