2017 © Pedro Peláez
 

library php-rsa

A PHP class that uses RSA algorithm for encryption and decryption.

image

sy-records/php-rsa

A PHP class that uses RSA algorithm for encryption and decryption.

  • Sunday, July 22, 2018
  • by sy-records
  • Repository
  • 0 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

php-rsa

A PHP class that uses RSA algorithm for encryption and decryption., (*1)

Before looking at the example, you need to generate the public and private keys of the RSA., (*2)

If you don't know how to generate RSA public and private keys, read this blog post: How does PHP use OpenSSL to generate the public and private keys needed for RSA encryption and decryption?, (*3)

Installation

You can install the package using composer., (*4)

composer require sy-records/php-rsa -vvv

Usage

If you want to use the instantiation method, please check the following., (*5)

<?php
use syrecords\Rsa;

$privateKey = './key/private_key.pem'; // Private key path
$publicKey = './key/rsa_public_key.pem'; // Public key path
$rsa = new Rsa($privateKey, $publicKey);

$originData = 'https://qq52o.me';

# Encryption with a private key requires public key decryption, called "signature".
$ecryptionData = $rsa->privEncrypt($originData);
$decryptionData = $rsa->publicDecrypt($ecryptionData);

echo 'The data encrypted by the private key is:' . $ecryptionData.PHP_EOL;
echo 'The data after the public key is decrypted is: ' . $decryptionData;

echo '


'; # Encryption with a public key requires private key decryption, called "encryption". $ecryptionData = $rsa->publicEncrypt($originData); $decryptionData = $rsa->privDecrypt($ecryptionData); echo 'The data after public key encryption is:' . $ecryptionData.PHP_EOL; echo 'The data after the private key is decrypted is:' . $decryptionData;

If you want to call a static method, then look at this one!, (*6)

<?php
use syrecords\staticRsa;

$privateKey = file_get_contents('./key/private_key.pem'); // Private key path
$publicKey = file_get_contents('./key/rsa_public_key.pem'); // Public key path

$originData = 'https://qq52o.me';

$ecryptionData = staticRsa::privEncrypt($originData,$privateKey);
$decryptionData = staticRsa::publicDecrypt($ecryptionData,$publicKey);

echo 'The data encrypted by the private key is:' . $ecryptionData.PHP_EOL;
echo 'The data after the public key is decrypted is: ' . $decryptionData;

echo '


'; $ecryptionData = staticRsa::publicEncrypt($originData,$publicKey); $decryptionData = staticRsa::privDecrypt($ecryptionData,$privateKey); echo 'The data after public key encryption is:' . $ecryptionData.PHP_EOL; echo 'The data after the private key is decrypted is:' . $decryptionData;

License

Apache-2.0, (*7)

The Versions

22/07 2018

dev-master

9999999-dev

A PHP class that uses RSA algorithm for encryption and decryption.

  Sources   Download

Apache-2.0

The Requires

  • php >= 5.4.0

 

php rsa php-rsa

22/07 2018

v1.1

1.1.0.0

A PHP class that uses RSA algorithm for encryption and decryption.

  Sources   Download

Apache-2.0

The Requires

  • php >= 5.4.0

 

php rsa php-rsa

22/07 2018

v1.0

1.0.0.0

A PHP class that uses RSA algorithm for encryption and decryption.

  Sources   Download

Apache-2.0

The Requires

  • php >= 5.4.0

 

php rsa php-rsa