Advertisement
Guest User

Untitled

a guest
Dec 15th, 2021
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. <?php
  2.  
  3. require __DIR__ . '/vendor/autoload.php';
  4.  
  5.   use phpseclib\Crypt\RSA;
  6.  
  7.   function rsaEncryptionOaepSha256 ($publicKey, $plaintext) {
  8.     $rsa = new RSA;
  9.     $rsa->loadKey($publicKey);
  10.     $rsa->setHash('sha256');
  11.     $rsa->setMGFHash('sha256');
  12.     return $rsa->encrypt($plaintext);
  13.   }
  14.  
  15.   function rsaDecryptionOaepSha256 ($privateKey, $ciphertext) {
  16.     $rsa = new RSA;
  17.     $rsa->loadKey($privateKey);
  18.     $rsa->setHash('sha256');
  19.     $rsa->setMGFHash('sha256');
  20.     return $rsa->decrypt($ciphertext);
  21.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement