Encrypt and Decrypt in RSA Public_key MOD

3

I am trying to encrypt strings in RSA, but I did not succeed.

I've tried this way (with phpseclib lib):

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '...');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'donotcache=153265'.mt_rand(1111111,9999999).'&username=abc'); 
$data = curl_exec($ch);
$json = json_decode($data);
$key = $json->{'publickey_mod'};

$privatekey = $key;

$rsa = new Crypt_RSA();
$rsa->loadKey($privatekey);

$plaintext = new Math_BigInteger('teste');
echo $rsa->_exponentiate($plaintext)->toBytes();

And this is the return:

  

Fatal error: Uncaught Error: Call to a member function abs () on null in C: \ xampp \ htdocs \ phpseclib1.0.11 \ Math \ BigInteger.php: 1683 Stack trace: # 0 C: \ xampp \ htdocs \ php: \ php \ phpcllib1.0.11 \ Crypt \ RSA.php (2194): Math_BigInteger-> modPow (NULL, NULL) # 1 C: \ xampp \ htdocs \ phpseclib1.0.11 \ rsa.php (10): Crypt_RSA- > _exponentiate (Object (Math_BigInteger)) # 2 {main} thrown in C: \ xampp \ htdocs \ phpseclib1.0.11 \ Math \ BigInteger.php on line 1683

I wanted to know if you can encrypt / decrypt in a simpler way, or how to resolve this error.

Output from publickey_mod ($ key):

c1b2bafb799b023c9b56e3e7375dc4ee77f6ee7aa28c274d919205774ae5e9941144333efebfa2bd34a3b5dfd7770da09237394cfe0e3b88f9f3543757a145bd0669d51344d611531fed466eb0a478c23cea404a42acfb426785fa0645bedb97c474e0da17612b62933166106d0f7866e379e4265bcd480b4b843f9e5c6025cc51ed22136ca34ce2e42fc19e4ee7f490304c526b6e389f9fcce1d0766d7a8af958112a163a88c44094533338019af9217e3eb804e26a763e79f68102d46dd88339e0f97ba0581b954c89d979a6d1ab3b4664e7660a0c35a5f00de64e2950ed7659bc9bee2582be987980d01461f12da5cbcf463d9607ac6616bfe57d7dc90217
  

Remembering that publickey_mod changes every refresh (post on page)

    
asked by anonymous 27.07.2018 / 02:42

0 answers