我对OpenPGP比较陌生,但我目前正在尝试使用OpenPGP.js在用户设备上加密消息,并在我的服务器上使用_2768164解密该消息 . 双方现在都可以对自己的消息进行加密和解密 - 问题是:一旦我在客户端对消息进行加密,就将其发送到服务器并尝试在那里解密它不起作用,反之亦然 .

有什么观点我可以检查问题是什么吗?

我尝试使用an online PGP en- and decryption service并且它解码服务器端(OpenPGP PHP)消息没有问题,并在客户端加密消息上给出"checksum mismatch"错误,所以我认为它可能是客户端 . 我正在使用localstorage来存储客户端的私钥和公钥以及服务器端的.asc文件,如果这很重要的话 . 公钥交换工作正常 .

服务器端:加密:

$key = OpenPGP_Message::parse(OpenPGP::unarmor($public, "PGP PUBLIC KEY BLOCK"));
$data = new OpenPGP_LiteralDataPacket($string, array('format' => 'u', 'filename' => 'stuff.txt'));
$encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message(array($data)));
$enc = OpenPGP::enarmor($encrypted->to_bytes(), "PGP MESSAGE");
$enc =  wordwrap($enc, 64, "\n", 1);
return $enc;

解密:

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

            $text = $decrypted->packets[0]->data;
        }
        return $text;

客户:ENCRYPT:

const options = {
                data: string,
                publicKeys: openpgp.key.readArmored(key).keys
            }
            openpgp.encrypt(options).then(ciphertext => {
                encrypted = ciphertext.data;
                callback(encrypted);
            })

解密:

const privKeyObj = openpgp.key.readArmored(storage.get("crypt.private")).keys[0]
        await privKeyObj.decrypt(storage.get("crypt.pass"))

        const options = {
            message: openpgp.message.readArmored(encrypted),     // parse armored message
            publicKeys: openpgp.key.readArmored(storage.get("crypt.public")).keys,    // for verification (optional)
            privateKeys: [privKeyObj]                            // for decryption
        }

        openpgp.decrypt(options).then(plaintext => {
            console.log(plaintext.data);
            callback(plaintext.data);
        });