singpolyma / openpgp-php

OpenPGP.php is a pure-PHP implementation of the OpenPGP Message Format (RFC 4880).
http://singpolyma.github.io/openpgp-php/
The Unlicense
179 stars 69 forks source link

Uncaught Exception: Data is already unencrypted #102

Closed diegoot-dev closed 3 years ago

diegoot-dev commented 3 years ago

Hi, i have a decryption issue:

Fatal error: Uncaught Exception: Data is already unencrypted in D:\wamp64\www\openpgp-php\lib\openpgp_crypt_symmetric.php on line 177

This is my code:

function decryptJson($message){

$msgASCII = $message;
$keyASCII = file_get_contents(dirname(__FILE__) . '/../keys/privateKey.txt');

$keyEncrypted = OpenPGP_Message::parse(OpenPGP::unarmor($keyASCII, 'PGP PRIVATE KEY BLOCK'));
var_dump($keyEncrypted);
foreach($keyEncrypted as $p) {
    if(!($p instanceof OpenPGP_SecretKeyPacket)) continue;
    $key = OpenPGP_Crypt_Symmetric::decryptSecretKey("test", $p);
    $msg = OpenPGP_Message::parse(OpenPGP::unarmor($msgASCII, 'PGP MESSAGE'));
    $decryptor = new OpenPGP_Crypt_RSA($key);
    $decrypted = $decryptor->decrypt($msg);
}

}

image

image

The error occurs because there are some null values in the Packet. Why does that happen?

The keys, encryption and decryption works fine in others projects with JAVA or Javascript.

Thanks!

singpolyma commented 3 years ago

Those NULL are fine. This exception only occurs when trying to decrypt data or key this is not actually encrypted. Could you post an example of data and key that produce this error for you?