Improve example with password encryption in README
This commit is contained in:
parent
a6dd8a9d2c
commit
73ab545c3e
78
README.md
78
README.md
|
@ -50,48 +50,18 @@ var openpgp = require('openpgp'); // use as CommonJS, AMD, ES6 module or via win
|
||||||
|
|
||||||
openpgp.initWorker({ path:'openpgp.worker.js' }) // set the relative web worker path
|
openpgp.initWorker({ path:'openpgp.worker.js' }) // set the relative web worker path
|
||||||
|
|
||||||
openpgp.config.aead_protect = true // activate fast AES-GCM mode (experimental)
|
openpgp.config.aead_protect = true // activate fast AES-GCM mode (not yet OpenPGP standard)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Encrypt and decrypt *String* data with a password
|
#### Encrypt and decrypt *Uint8Array* data with a password
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var options, encrypted;
|
var options, encrypted;
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
data: 'Hello, World!', // input as String
|
data: new Uint8Array([0x01, 0x01, 0x01]), // input as Uint8Array (or String)
|
||||||
passwords: ['secret stuff'] // multiple passwords possible
|
passwords: ['secret stuff'], // multiple passwords possible
|
||||||
};
|
armor: false // don't ASCII armor (for Uint8Array output)
|
||||||
|
|
||||||
openpgp.encrypt(options).then(function(ciphertext) {
|
|
||||||
encrypted = ciphertext.data; // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
options = {
|
|
||||||
message: openpgp.message.readArmored(encrypted), // parse armored message
|
|
||||||
password: 'secret stuff' // decrypt with password
|
|
||||||
};
|
|
||||||
|
|
||||||
openpgp.decrypt(options).then(function(plaintext) {
|
|
||||||
return plaintext.data; // 'Hello, World!'
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Encrypt and decrypt *Uint8Array* data with PGP keys
|
|
||||||
|
|
||||||
```js
|
|
||||||
var options, encrypted;
|
|
||||||
|
|
||||||
var pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----';
|
|
||||||
var privkey = '-----BEGIN PGP PRIVATE KEY BLOCK ... END PGP PRIVATE KEY BLOCK-----';
|
|
||||||
|
|
||||||
options = {
|
|
||||||
data: new Uint8Array([0x01, 0x01, 0x01]), // input as Uint8Array
|
|
||||||
publicKeys: openpgp.key.readArmored(pubkey).keys, // for encryption
|
|
||||||
privateKeys: openpgp.key.readArmored(privkey).keys, // for signing (optional)
|
|
||||||
armor: false // don't ASCII armor
|
|
||||||
};
|
};
|
||||||
|
|
||||||
openpgp.encrypt(options).then(function(ciphertext) {
|
openpgp.encrypt(options).then(function(ciphertext) {
|
||||||
|
@ -101,10 +71,9 @@ openpgp.encrypt(options).then(function(ciphertext) {
|
||||||
|
|
||||||
```js
|
```js
|
||||||
options = {
|
options = {
|
||||||
message: openpgp.message.read(encrypted), // parse encrypted bytes
|
message: openpgp.message.read(encrypted), // parse encrypted bytes
|
||||||
publicKeys: openpgp.key.readArmored(pubkey).keys, // for verification (optional)
|
password: 'secret stuff' // decrypt with password
|
||||||
privateKey: openpgp.key.readArmored(privkey).keys[0], // for decryption
|
format: 'binary' // output as Uint8Array
|
||||||
format: 'binary' // output as Uint8Array
|
|
||||||
};
|
};
|
||||||
|
|
||||||
openpgp.decrypt(options).then(function(plaintext) {
|
openpgp.decrypt(options).then(function(plaintext) {
|
||||||
|
@ -112,6 +81,37 @@ openpgp.decrypt(options).then(function(plaintext) {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Encrypt and decrypt *String* data with PGP keys
|
||||||
|
|
||||||
|
```js
|
||||||
|
var options, encrypted;
|
||||||
|
|
||||||
|
var pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----';
|
||||||
|
var privkey = '-----BEGIN PGP PRIVATE KEY BLOCK ... END PGP PRIVATE KEY BLOCK-----';
|
||||||
|
|
||||||
|
options = {
|
||||||
|
data: 'Hello, World!', // input as String (or Uint8Array)
|
||||||
|
publicKeys: openpgp.key.readArmored(pubkey).keys, // for encryption
|
||||||
|
privateKeys: openpgp.key.readArmored(privkey).keys, // for signing (optional)
|
||||||
|
};
|
||||||
|
|
||||||
|
openpgp.encrypt(options).then(function(ciphertext) {
|
||||||
|
encrypted = ciphertext.data; // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
options = {
|
||||||
|
message: openpgp.message.readArmored(encrypted), // parse armored message
|
||||||
|
publicKeys: openpgp.key.readArmored(pubkey).keys, // for verification (optional)
|
||||||
|
privateKey: openpgp.key.readArmored(privkey).keys[0], // for decryption
|
||||||
|
};
|
||||||
|
|
||||||
|
openpgp.decrypt(options).then(function(plaintext) {
|
||||||
|
return plaintext.data; // 'Hello, World!'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
#### Generate new key pair
|
#### Generate new key pair
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
Loading…
Reference in New Issue
Block a user