php rsa encryption

Solutions on MaxInterview for php rsa encryption by the best coders in the world

showing results for - "php rsa encryption"
Hannes
25 Aug 2018
1// Use phpseclib: http://phpseclib.sourceforge.net/
2<?php
3include('Crypt/RSA.php');
4
5$privatekey = file_get_contents('private.key');
6$rsa = new Crypt_RSA();
7$rsa->loadKey($privatekey);
8
9$plaintext = new Math_BigInteger('aaaaaa');
10echo $rsa->_exponentiate($plaintext)->toBytes();
11?>
Giovanni
04 Oct 2020
1<?php
2
3$publicKey = file_get_contents("public.key");
4$textToEncrypt = "My Plain Text" ;
5$cipherType = "RSA/ECB/PKCS1Padding"; //RSA, RSA/ECB/OAEPWithSHA-1AndMGF1Padding
6
7
8$curl = curl_init();
9
10curl_setopt_array($curl, array(
11  CURLOPT_URL => 'https://www.devglan.com/online-tools/rsa-encrypt',
12  CURLOPT_RETURNTRANSFER => true,
13  CURLOPT_ENCODING => '',
14  CURLOPT_MAXREDIRS => 10,
15  CURLOPT_TIMEOUT => 0,
16  CURLOPT_FOLLOWLOCATION => true,
17  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
18  CURLOPT_CUSTOMREQUEST => 'POST',
19  CURLOPT_POSTFIELDS =>'{
20    "textToEncrypt": "'.$textToEncrypt.'",
21    "publicKey": "'.$publicKey.'",
22    "keyType": "publicKeyForEncryption",
23    "cipherType": "'.$cipherType.'"
24}',
25  CURLOPT_HTTPHEADER => array(
26    'Content-Type: application/json'
27  ),
28));
29
30$response = curl_exec($curl);
31
32curl_close($curl);
33echo $response;
34
35?>
36