Module: openpgp

Requires

Members

(static) armor

Source:
See:

(static) AsyncProxy

Source:
See:
  • module:worker/async_proxy

(static) cleartext

Source:
See:

(static) config

Source:
See:

(static) crypto

Source:
See:

(static) enums

Source:
See:

(static) HKP

Source:
See:
  • module:hkp

(static) key

Source:
See:

(static) Keyid

Source:
See:

(static) Keyring

Source:
See:

(static) message

Source:
See:

(static) MPI

Source:
See:

(static) packet

Source:
See:

(static) S2K

Source:
See:

(static) util

Source:
See:

Methods

(static) decrypt(message, privateKey, publicKeys, sessionKey, password, format) → {Promise.<Object>}

Decrypts a message with the user's private key, a session key or a password. Either a private key, a session key or a password must be specified.
Parameters:
Name Type Description
message Message the message object with the encrypted data
privateKey Key (optional) private key with decrypted secret key data or session key
publicKeys Key | Array.<Key> (optional) array of public keys or single key, to verify signatures
sessionKey Object (optional) session key in the form: { data:Uint8Array, algorithm:String }
password String (optional) single password to decrypt the message
format String (optional) return data format either as 'utf8' or 'binary'
Source:
Returns:
decrypted and verified message in the form: { data:Uint8Array|String, filename:String, signatures:[{ keyid:String, valid:Boolean }] }
Type
Promise.<Object>

(static) decryptKey(privateKey, passphrase) → {Key}

Unlock a private key with your passphrase.
Parameters:
Name Type Description
privateKey Key the private key that is to be decrypted
passphrase String the user's passphrase chosen during key generation
Source:
Returns:
the unlocked private key
Type
Key

(static) decryptSessionKey(message, privateKey, password) → {Promise.<(Object|undefined)>}

Decrypt a symmetric session key with a private key or password. Either a private key or a password must be specified.
Parameters:
Name Type Description
message Message a message object containing the encrypted session key packets
privateKey Key (optional) private key with decrypted secret key data
password String (optional) a single password to decrypt the session key
Source:
Returns:
decrypted session key and algorithm in object form: { data:Uint8Array, algorithm:String } or 'undefined' if no key packets found
Type
Promise.<(Object|undefined)>

(static) destroyWorker()

Cleanup the current instance of the web worker.
Source:

(static) encrypt(data, publicKeys, privateKeys, passwords, filename, armor) → {Promise.<(String|Message)>}

Encrypts message text/data with public keys, passwords or both at once. At least either public keys or passwords must be specified. If private keys are specified, those will be used to sign the message.
Parameters:
Name Type Description
data String | Uint8Array text/data to be encrypted as JavaScript binary string or Uint8Array
publicKeys Key | Array.<Key> (optional) array of keys or single key, used to encrypt the message
privateKeys Key | Array.<Key> (optional) private keys for signing. If omitted message will not be signed
passwords String | Array.<String> (optional) array of passwords or a single password to encrypt the message
filename String (optional) a filename for the literal data packet
armor Boolean (optional) if the return value should be ascii armored or the message object
Source:
Returns:
encrypted ASCII armored message, or the full Message object if 'armor' is false
Type
Promise.<(String|Message)>

(static) encryptSessionKey(data, algorithm, publicKeys, passwords) → {Promise.<Message>}

Encrypt a symmetric session key with public keys, passwords, or both at once. At least either public keys or passwords must be specified.
Parameters:
Name Type Description
data Uint8Array the session key to be encrypted e.g. 16 random bytes (for aes128)
algorithm String algorithm of the symmetric session key e.g. 'aes128' or 'aes256'
publicKeys Key | Array.<Key> (optional) array of public keys or single key, used to encrypt the key
passwords String | Array.<String> (optional) passwords for the message
Source:
Returns:
the encrypted session key packets contained in a message object
Type
Promise.<Message>

(static) generateKey(userIds, passphrase, numBits, unlocked) → {Promise.<Object>}

Generates a new OpenPGP key pair. Currently only supports RSA keys. Primary and subkey will be of same type.
Parameters:
Name Type Description
userIds Array.<Object> array of user IDs e.g. [{ name:'Phil Zimmermann', email:[email protected]' }]
passphrase String (optional) The passphrase used to encrypt the resulting private key
numBits Number (optional) number of bits for the key creation. (should be 2048 or 4096)
unlocked Boolean (optional) If the returned secret part of the generated key is unlocked
Source:
Returns:
The generated key object in the form: { key:Key, privateKeyArmored:String, publicKeyArmored:String }
Type
Promise.<Object>

(static) getWorker() → {module:worker/async_proxy~AsyncProxy|null}

Returns a reference to the async proxy if the worker was initialized with openpgp.initWorker()
Source:
Returns:
the async proxy or null if not initialized
Type
module:worker/async_proxy~AsyncProxy | null

(static) initWorker(path, worker)

Set the path for the web worker script and create an instance of the async proxy
Parameters:
Name Type Description
path String relative path to the worker scripts, default: 'openpgp.worker.js'
worker Object alternative to path parameter: web worker initialized with 'openpgp.worker.js'
Source:

(static) sign(data, privateKeys, armor) → {Promise.<(String|CleartextMessage)>}

Signs a cleartext message.
Parameters:
Name Type Description
data String cleartext input to be signed
privateKeys Key | Array.<Key> array of keys or single key with decrypted secret key data to sign cleartext
armor Boolean (optional) if the return value should be ascii armored or the message object
Source:
Returns:
ASCII armored message or the message of type CleartextMessage
Type
Promise.<(String|CleartextMessage)>

(static) verify(publicKeys, message) → {Promise.<Object>}

Verifies signatures of cleartext signed message
Parameters:
Name Type Description
publicKeys Key | Array.<Key> array of publicKeys or single key, to verify signatures
message CleartextMessage cleartext message object with signatures
Source:
Returns:
cleartext with status of verified signatures in the form of: { data:String, signatures: [{ keyid:String, valid:Boolean }] }
Type
Promise.<Object>

(inner) checkString()

Input validation
Source:

(inner) createMessage(data, filename) → {Message}

Creates a message obejct either from a Uint8Array or a string.
Parameters:
Name Type Description
data String | Uint8Array the payload for the message
filename String the literal data packet's filename
Source:
Returns:
a message object
Type
Message

(inner) execute(cmd, message) → {Promise}

Command pattern that wraps synchronous code into a promise.
Parameters:
Name Type Description
cmd function The synchronous function with a return value to be wrapped in a promise
message String A human readable error Message
Source:
Returns:
The promise wrapped around cmd
Type
Promise

(inner) formatUserIds()

Format user ids for internal use.
Source:

(inner) nativeAEAD() → {Boolean}

Check for AES-GCM support and configuration by the user. Only browsers that implement the current WebCrypto specification support native AES-GCM.
Source:
Returns:
If authenticated encryption should be used
Type
Boolean

(inner) onError(message, error)

Global error handler that logs the stack trace and rethrows a high lvl error message.
Parameters:
Name Type Description
message String A human readable high level error Message
error Error The internal error that caused the failure
Source:

(inner) parseMessage(message, format) → {Object}

Parse the message given a certain format.
Parameters:
Name Type Description
message Message the message object to be parse
format String the output format e.g. 'utf8' or 'binary'
Source:
Returns:
the parse data in the respective format
Type
Object

(inner) toArray(param) → {Array.<Object>|undefined}

Normalize parameter to an array if it is not undefined.
Parameters:
Name Type Description
param Object the parameter to be normalized
Source:
Returns:
the resulting array or undefined
Type
Array.<Object> | undefined