You should use

signAndEncryptMessage

http://openpgpjs.org/openpgpjs/doc/openpgp.js.html#line93

If you want to encrypt - you need public key of the recipient, if you
want to decrypt - your private key;
If you want to sign - your private key. If you want to verify signature
- public key of the sender.

W dniu 18.08.2015 o 23:09, Bruno Barberi Gnecco pisze:
> Hi,
>
> I posted this as an issue but it seems more appropriate to this list.
>
> Is it possible to encrypt with a private key and decrypt with a public key? I 
> want to send 
> data that is guaranteed to be from a sender and I'd rather not send it as 
> clear text, so 
> just signClearMessage() is not an option. decryptAndVerifyMessage() requires 
> both the 
> public and private keys, so also not an option.
>
> I can encrypt with a private key easily:
>
>      var publicKey = openpgp.key.readArmored(fs.readFileSync('public.key', 
> 'utf-8'));
>      var privateKey = openpgp.key.readArmored(fs.readFileSync('private.key', 
> 'utf-8')).keys[0];
>      privateKey.decrypt(PASSPHRASE);
>      openpgp.encryptMessage(privateKey, text).then(function(pgpMessage){ // 
> yes, private });
>
> But trying to decrypt with a public key does not work. This returns Error: 
> Private key is 
> not decrypted.
>
>      pgpMessage = openpgp.message.readArmored(pgpMessage);
>      openpgp.decryptMessage(publicKey.keys[0], 
> pgpMessage).then(function(plain) {
>          ....
>      });
>
> But publicKey.keys[0].decrypt(PASSPHRASE) throw Error: Nothing to decrypt in 
> a public key.
>
> Any tips?
>
> _______________________________________________
>
> http://openpgpjs.org
> Subscribe/unsubscribe: http://list.openpgpjs.org


-- 
Paweł Górny
mailto:[email protected] http://pawelgorny.com
* only way to feel the noise is when it's good and loud *

In reply please use the key: 0xF0F72044

_______________________________________________

http://openpgpjs.org
Subscribe/unsubscribe: http://list.openpgpjs.org

Reply via email to