I'm trying to decrypt a string using phpseclib.
My hashed string is being generated from a javascript library called jsencrypt. The result of the encryption is saved in a database.
Afterwards I'm using phpseclib3 to try and decrypt the string using this:
<?php
require_once ("vendor/autoload.php"); // i used composer to install phpseclib
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Crypt\RSA;
$private_key = RSA::loadFormat('PKCS8', file_get_contents('key.pem'), $password = false);
$key = PublicKeyLoader::load($private_key)->withHash('sha512/256')->withMGFHash('sha512/256');
$hashed_string = base64_decode("...");
echo $key->decrypt($hashed_string);
?>
But when I run the code I get the following error:
Fatal error: Uncaught LengthException: Ciphertext representative too long in /vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA/PrivateKey.php:389
I've also tried decrypting the string using openssl_decrypt
with no luck:
$privateKey = '-----BEGIN RSA PRIVATE KEY-----
PRIVATE KEY HERE...
-----END RSA PRIVATE KEY-----';
$encrypt_method = "AES-256-CBC";
$plain_text = openssl_decrypt('...', $encrypt_method, $privateKey, 0);
echo $plain_text;
Does anyone know how I can go about decrypting the hashed string?