Add cleartext signing example to README
This commit is contained in:
parent
5ffb532f9e
commit
5fa35ea1c0
34
README.md
34
README.md
|
@ -151,6 +151,40 @@ var pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----'
|
||||||
hkp.upload(pubkey).then(function() { ... });
|
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
|
### 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).
|
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).
|
||||||
|
|
Loading…
Reference in New Issue
Block a user