# Module: crypto/crypto

Provides functions for asymmetric encryption and decryption as well as key generation and parameter handling for all public-key cryptosystems.

Source:
  - crypto/crypto.js, line 20

### Methods

#### (async, static) generateParams(algo, bits, oid) → {Promise.<{publicParams: {Object}, privateParams: {Object}}>}

Generate algorithm-specific key parameters

##### Parameters:

Name | Type | Description
--- | --- | ---
`algo` | module:enums.publicKey | The public key algorithm
`bits` | Integer | Bit length for RSA keys
`oid` | module:type/oid | Object identifier for ECC keys

Source:
  - crypto/crypto.js, line 330

##### Returns:

The parameters referenced by name.

Type
  Promise.<{publicParams: {Object}, privateParams: {Object}}>

#### (static) generateSessionKey(algo) → {Uint8Array}

Generating a session key for the specified symmetric algorithm See RFC 4880 9.2 for algorithms.

##### Parameters:

Name | Type | Description
--- | --- | ---
`algo` | module:enums.symmetric | Symmetric encryption algorithm

Source:
  - crypto/crypto.js, line 457

##### Returns:

Random bytes as a string to be used as a key.

Type
  Uint8Array

#### (static) getAEADMode(algo) → {Object}

Get implementation of the given AEAD mode

##### Parameters:

Name | Type | Description
--- | --- | ---
`algo` | enums.aead |

Source:
  - crypto/crypto.js, line 468

##### Throws:

on invalid algo

Type
  Error

##### Returns:

Type
  Object

#### (static) getCurvePayloadSize(algo, oidopt)

Get encoded secret size for a given elliptic algo

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`algo` | module:enums.publicKey |  | alrogithm identifier
`oid` | module:type/oid | <optional> | curve OID if needed by algo

Source:
  - crypto/crypto.js, line 491

#### (static) getPreferredCurveHashAlgo(algo, oidopt)

Get preferred signing hash algo for a given elliptic algo

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`algo` | module:enums.publicKey |  | alrogithm identifier
`oid` | module:type/oid | <optional> | curve OID if needed by algo

Source:
  - crypto/crypto.js, line 513

#### (async, static) getPrefixRandom(algo) → {Promise.<Uint8Array>}

Generates a random byte prefix for the specified algorithm See RFC 4880 9.2 for algorithms.

##### Parameters:

Name | Type | Description
--- | --- | ---
`algo` | module:enums.symmetric | Symmetric encryption algorithm

Source:
  - crypto/crypto.js, line 444

##### Returns:

Random bytes with length equal to the block size of the cipher, plus the last two bytes repeated.

Type
  Promise.<Uint8Array>

#### (static) parseEncSessionKeyParams(algo, bytes) → {Object}

Returns the types comprising the encrypted session key of an algorithm

##### Parameters:

Name | Type | Description
--- | --- | ---
`algo` | module:enums.publicKey | The key algorithm
`bytes` | Uint8Array | The key material to parse

Source:
  - crypto/crypto.js, line 256

##### Returns:

The session key parameters referenced by name.

Type
  Object

#### (static) parsePrivateKeyParams(algo, bytes, publicParams) → {Object}

Parse private key material in binary form to get the key parameters

##### Parameters:

Name | Type | Description
--- | --- | ---
`algo` | module:enums.publicKey | The key algorithm
`bytes` | Uint8Array | The key material to parse
`publicParams` | Object | (ECC only) public params, needed to format some private params

Source:
  - crypto/crypto.js, line 204

##### Returns:

Number of read bytes plus the key parameters referenced by name.

Type
  Object

#### (static) parsePublicKeyParams(algo, bytes) → {Object}

Parse public key material in binary form to get the key parameters

##### Parameters:

Name | Type | Description
--- | --- | ---
`algo` | module:enums.publicKey | The key algorithm
`bytes` | Uint8Array | The key material to parse

Source:
  - crypto/crypto.js, line 142

##### Returns:

Number of read bytes plus key parameters referenced by name.

Type
  Object

#### (async, static) publicKeyDecrypt(algo, publicKeyParams, privateKeyParams, sessionKeyParams, fingerprint, randomPayloadopt) → {Promise.<Uint8Array>}

Decrypts data using specified algorithm and private key parameters. See RFC 4880 5.5.3

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`algo` | module:enums.publicKey |  | Public key algorithm
`publicKeyParams` | Object |  | Algorithm-specific public key parameters
`privateKeyParams` | Object |  | Algorithm-specific private key parameters
`sessionKeyParams` | Object |  | Encrypted session key parameters
`fingerprint` | Uint8Array |  | Recipient fingerprint
`randomPayload` | Uint8Array | <optional> | Data to return on decryption error, instead of throwing (needed for constant-time processing in RSA and ElGamal)

Source:
  - crypto/crypto.js, line 98

##### Throws:

on sensitive decryption error, unless `randomPayload` is given

Type
  Error

##### Returns:

Decrypted data.

Type
  Promise.<Uint8Array>

#### (async, static) publicKeyEncrypt(keyAlgo, symmetricAlgo, publicParams, data, fingerprint) → {Promise.<Object>}

Encrypts data using specified algorithm and public key parameters. See RFC 4880 9.1 for public key algorithms.

##### Parameters:

Name | Type | Description
--- | --- | ---
`keyAlgo` | module:enums.publicKey | Public key algorithm
`symmetricAlgo` | module:enums.symmetric | Cipher algorithm
`publicParams` | Object | Algorithm-specific public key parameters
`data` | Uint8Array | Session key data to be encrypted
`fingerprint` | Uint8Array | Recipient fingerprint

Source:
  - crypto/crypto.js, line 49

##### Returns:

Encrypted session key parameters.

Type
  Promise.<Object>

#### (static) serializeParams(algo, params) → {Uint8Array}

Convert params to MPI and serializes them in the proper order

##### Parameters:

Name | Type | Description
--- | --- | ---
`algo` | module:enums.publicKey | The public key algorithm
`params` | Object | The key parameters indexed by name

Source:
  - crypto/crypto.js, line 306

##### Returns:

The array containing the MPIs.

Type
  Uint8Array

#### (async, static) validateParams(algo, publicParams, privateParams) → {Promise.<Boolean>}

Validate algorithm-specific key parameters

##### Parameters:

Name | Type | Description
--- | --- | ---
`algo` | module:enums.publicKey | The public key algorithm
`publicParams` | Object | Algorithm-specific public key parameters
`privateParams` | Object | Algorithm-specific private key parameters

Source:
  - crypto/crypto.js, line 386

##### Returns:

Whether the parameters are valid.

Type
  Promise.<Boolean>

#### (inner) checkSupportedCurve(oid)

Check whether the given curve OID is supported

##### Parameters:

Name | Type | Description
--- | --- | ---
`oid` | module:type/oid | EC object identifier

Source:
  - crypto/crypto.js, line 478

##### Throws:

if curve is not supported

Type
  UnsupportedError