From 5fa35ea1c0b26f4bcfcda338e5d6801ef19a38fd Mon Sep 17 00:00:00 2001 From: Will Hilton Date: Thu, 5 Jan 2017 23:50:07 -0500 Subject: [PATCH] Add cleartext signing example to README --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 1593f609..5f004054 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,40 @@ var pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----' hkp.upload(pubkey).then(function() { ... }); ``` +#### Sign and verify cleartext messages + +```js +var options, cleartext, validity; + +var pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----'; +var privkey = '-----BEGIN PGP PRIVATE KEY BLOCK ... END PGP PRIVATE KEY BLOCK-----'; +``` + +```js +options = { + data: 'Hello, World!', // input as String (or Uint8Array) + privateKeys: openpgp.key.readArmored(privkey).keys // for signing +}; + +openpgp.sign(options).then(function(signed) { + cleartext = signed.data; // '-----BEGIN PGP SIGNED MESSAGE ... END PGP SIGNATURE-----' +}); +``` + +```js +options = { + message: openpgp.cleartext.readArmored(cleartext), // parse armored message + publicKeys: openpgp.key.readArmored(pubkey).keys // for verification +}; + +openpgp.verify(options).then(function(verified) { + validity = verified.signatures[0].valid; // true + if (validity) { + console.log('signed by key id ' + verified.signatures[0].keyid.toHex()); + } +}); +``` + ### Documentation A jsdoc build of our code comments is available at [doc/index.html](http://openpgpjs.org/openpgpjs/doc/index.html). Public calls should generally be made through the OpenPGP object [doc/openpgp.html](http://openpgpjs.org/openpgpjs/doc/module-openpgp.html).