加密消息时出错:私钥未解密
Error encrypting message: Private key is not decrypted
我正在尝试使用 OpenPgpjs 对消息进行加密和签名。
但是我一直收到这个错误"Error encrypting message: Private key is not decrypted"
这是我试过的:
var openpgp = require('openpgp');
var publicKey = [].join("\n"); //This has the complete key. Removed for representation
var privateKey = [].join("\n"); //This has the complete key. Removed for representation
var publicKeys = openpgp.key.readArmored(publicKey).keys;
var privateKeys = openpgp.key.readArmored(privateKey).keys;
encryptionOptions = {
data : 'Example Test',
publicKeys : publicKeys,
privateKeys : privateKeys
};
return openpgp.encrypt(encryptionOptions).then(function(ciphertext) {
encryptedData = ciphertext.data;
console.log(ciphertext);
return encryptedData;
});
签名需要解密私钥:
var pub = openpgp.key.readArmored(publicKey);
var priv = openpgp.key.readArmored(privateKey);
// decrypt the private key with password
var success = priv.keys[0].decrypt('my-secret-password');
var options = {
data: 'Hello, World!',
publicKeys: pub.keys,
privateKeys: priv.keys // for signing (optional)
};
openpgp.encrypt(options).then(function(ciphertext) {
console.log (ciphertext.data);
});
我正在尝试使用 OpenPgpjs 对消息进行加密和签名。
但是我一直收到这个错误"Error encrypting message: Private key is not decrypted"
这是我试过的:
var openpgp = require('openpgp');
var publicKey = [].join("\n"); //This has the complete key. Removed for representation
var privateKey = [].join("\n"); //This has the complete key. Removed for representation
var publicKeys = openpgp.key.readArmored(publicKey).keys;
var privateKeys = openpgp.key.readArmored(privateKey).keys;
encryptionOptions = {
data : 'Example Test',
publicKeys : publicKeys,
privateKeys : privateKeys
};
return openpgp.encrypt(encryptionOptions).then(function(ciphertext) {
encryptedData = ciphertext.data;
console.log(ciphertext);
return encryptedData;
});
签名需要解密私钥:
var pub = openpgp.key.readArmored(publicKey);
var priv = openpgp.key.readArmored(privateKey);
// decrypt the private key with password
var success = priv.keys[0].decrypt('my-secret-password');
var options = {
data: 'Hello, World!',
publicKeys: pub.keys,
privateKeys: priv.keys // for signing (optional)
};
openpgp.encrypt(options).then(function(ciphertext) {
console.log (ciphertext.data);
});