chunk_id large_stringlengths 36 36 | doc_type large_stringclasses 2
values | category large_stringclasses 17
values | document large_stringclasses 50
values | version_raw large_stringclasses 590
values | chunk_index int64 0 262 | text large_stringlengths 11 5.69k | file_path large_stringclasses 882
values |
|---|---|---|---|---|---|---|---|
2c10d0bf-ee5a-5017-a52e-8bf6554182ab | docs | nodejs | nodejs_crypto | 7x | 27 | ### hash.digest([encoding])[#](#crypto_hash_digest_encoding)
Added in: v0.1.92
Calculates the digest of all of the data passed to be hashed (using the
[`hash.update()`](#crypto_hash_update_data_input_encoding) method). The `encoding` can be `'hex'`, `'latin1'` or
`'base64'`. If `encoding` is provided a string will be... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
fe35a218-cd1e-522b-a029-daa313aa6e48 | docs | nodejs | nodejs_crypto | 7x | 28 | encoding of `'utf8'` is enforced. If `data` is a [`Buffer`](buffer.html) then
`input_encoding` is ignored.
This can be called many times with new data as it is streamed.
## Class: Hmac[#](#crypto_class_hmac)
Added in: v0.1.94
The `Hmac` Class is a utility for creating cryptographic HMAC digests. It can
be used in o... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
661bb86e-2818-5e63-a9d2-9ed38e2f605c | docs | nodejs | nodejs_crypto | 7x | 29 | const data = hmac.read();
if (data)
console.log(data.toString('hex'));
// Prints:
// 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
});
hmac.write('some data to hash');
hmac.end();
```
Example: Using `Hmac` and piped streams:
```None
const crypto = require('crypto');
const fs = re... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
03ff68b7-40e2-5f41-94f5-eedda0ee9235 | docs | nodejs | nodejs_crypto | 7x | 30 | ### hmac.digest([encoding])[#](#crypto_hmac_digest_encoding)
Added in: v0.1.94
Calculates the HMAC digest of all of the data passed using [`hmac.update()`](#crypto_hmac_update_data_input_encoding).
The `encoding` can be `'hex'`, `'latin1'` or `'base64'`. If `encoding` is
provided a string is returned; otherwise a [`B... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
f1666b87-8d70-550d-aeb8-080a444f2b59 | docs | nodejs | nodejs_crypto | 7x | 31 | encoding of `'utf8'` is enforced. If `data` is a [`Buffer`](buffer.html) then
`input_encoding` is ignored.
This can be called many times with new data as it is streamed.
## Class: Sign[#](#crypto_class_sign)
Added in: v0.1.92
The `Sign` Class is a utility for generating signatures. It can be used in one
of two ways... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
1222e72e-2a99-5cf8-bb35-ede52d31fa83 | docs | nodejs | nodejs_crypto | 7x | 32 | sign.write('some data to sign');
sign.end();
const privateKey = getPrivateKeySomehow();
console.log(sign.sign(privateKey, 'hex'));
// Prints: the calculated signature
```
Example: Using the [`sign.update()`](#crypto_sign_update_data_input_encoding) and [`sign.sign()`](#crypto_sign_sign_private_key_output_format) meth... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
3df86814-5309-5a23-b38e-0c79209e6fd4 | docs | nodejs | nodejs_crypto | 7x | 33 | sign.update('some data to sign');
const privateKey =
`-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIF+jnWY1D5kbVYDNvxxo/Y+ku2uJPDwS0r/VuPZQrjjVoAoGCCqGSM49
AwEHoUQDQgAEurOxfSxmqIRYzJVagdZfMMSjRNNhB8i3mXyIMq704m2m52FdfKZ2
pQhByd5eyj3lgZ7m7jbchtdgyOF8Io/1ng==
-----END EC PRIVATE KEY-----`;
console.log(sign.sign(privateKey).t... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
13208636-39da-57b8-b4a3-c7a0d032aba6 | docs | nodejs | nodejs_crypto | 7x | 34 | * `passphrase`: [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) - passphrase for the private key
The `output_format` can specify one of `'latin1'`, `'hex'` or `'base64'`. If
`output_format` is provided a string is returned; otherwise a [`Buffer`](buffer.html) is
returned... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
d0e1ea98-6e9c-57cb-8fca-6584f1fab315 | docs | nodejs | nodejs_crypto | 7x | 35 | `input_encoding` is ignored.
This can be called many times with new data as it is streamed.
## Class: Verify[#](#crypto_class_verify)
Added in: v0.1.92
The `Verify` class is a utility for verifying signatures. It can be used in one
of two ways:
* As a writable [stream](stream.html) where written data is used to va... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
a9a074af-ec2b-59c8-b7b1-7019c79d9132 | docs | nodejs | nodejs_crypto | 7x | 36 | console.log(verify.verify(publicKey, signature));
// Prints: true or false
```
Example: Using the [`verify.update()`](#crypto_verifier_update_data_input_encoding) and [`verify.verify()`](#crypto_verifier_verify_object_signature_signature_format) methods:
```None
const crypto = require('crypto');
const verify = crypto... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
27ae447f-8d6f-56ce-9b59-013adc3c6d1f | docs | nodejs | nodejs_crypto | 7x | 37 | encoding of `'utf8'` is enforced. If `data` is a [`Buffer`](buffer.html) then
`input_encoding` is ignored.
This can be called many times with new data as it is streamed.
### verifier.verify(object, signature[, signature\_format])[#](#crypto_verifier_verify_object_signature_signature_format)
Added in: v0.1.92
Verifi... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
4fd89115-f060-5ed0-8215-9dffcbac52b8 | docs | nodejs | nodejs_crypto | 7x | 38 | called. Multiple calls to `verify.verify()` will result in an error being
thrown.
## `crypto` module methods and properties[#](#crypto_crypto_module_methods_and_properties)
### crypto.constants[#](#crypto_crypto_constants)
Added in: v6.3.0
Returns an object containing commonly used constants for crypto and security... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
9bfe57d3-fdc4-5c4a-a0dc-11db716cc840 | docs | nodejs | nodejs_crypto | 7x | 39 | ### crypto.fips[#](#crypto_crypto_fips)
Added in: v6.0.0
Property for checking and controlling whether a FIPS compliant crypto provider is
currently in use. Setting to true requires a FIPS build of Node.js.
### crypto.createCipher(algorithm, password)[#](#crypto_crypto_createcipher_algorithm_password)
Added in: v0.... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
c51417e3-8b90-5e02-8999-5f85f71ce163 | docs | nodejs | nodejs_crypto | 7x | 40 | iteration, and no salt. The lack of salt allows dictionary attacks as the same
password always creates the same key. The low iteration count and
non-cryptographically secure hash algorithm allow passwords to be tested very
rapidly.
In line with OpenSSL's recommendation to use pbkdf2 instead of
[`EVP_BytesToKey`](https... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
c1984533-1a68-5b25-b6ed-c46b17ce9d4c | docs | nodejs | nodejs_crypto | 7x | 41 | available cipher algorithms.
The `key` is the raw key used by the `algorithm` and `iv` is an
[initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded strings or
[buffers](buffer.html).
### crypto.createCredentials(details)[#](#crypto_crypto_createcredential... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
ad09a562-61db-524a-8f09-9edbc41c5dd0 | docs | nodejs | nodejs_crypto | 7x | 42 | Returns a `tls.SecureContext`, as-if [`tls.createSecureContext()`](tls.html#tls_tls_createsecurecontext_options) had been
called.
### crypto.createDecipher(algorithm, password)[#](#crypto_crypto_createdecipher_algorithm_password)
Added in: v0.1.94
Creates and returns a `Decipher` object that uses the given `algorith... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
a62c8cba-a68b-545e-9998-42e58321f192 | docs | nodejs | nodejs_crypto | 7x | 43 | their own using [`crypto.pbkdf2()`](#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback) and to use [`crypto.createDecipheriv()`](#crypto_crypto_createdecipheriv_algorithm_key_iv)
to create the `Decipher` object.
### crypto.createDecipheriv(algorithm, key, iv)[#](#crypto_crypto_createdecipheriv_algor... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
e3e8acbb-c90a-5498-aeb3-9d8579051df1 | docs | nodejs | nodejs_crypto | 7x | 44 | ### crypto.createDiffieHellman(prime[, prime\_encoding][, generator][, generator\_encoding])[#](#crypto_crypto_creatediffiehellman_prime_prime_encoding_generator_generator_encoding)
History
| Version | Changes |
| --- | --- |
| v6.0.0 | The default for the encoding parameters changed from `binary` to `utf8`. |
| v0.1... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
c5f550c5-d27a-5777-9977-40ead2c7fd76 | docs | nodejs | nodejs_crypto | 7x | 45 | ### crypto.createDiffieHellman(prime\_length[, generator])[#](#crypto_crypto_creatediffiehellman_prime_length_generator)
Added in: v0.5.0
Creates a `DiffieHellman` key exchange object and generates a prime of
`prime_length` bits using an optional specific numeric `generator`.
If `generator` is not specified, the valu... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
54d3b81c-d8ba-51ad-a076-da0fed7e9764 | docs | nodejs | nodejs_crypto | 7x | 46 | The `algorithm` is dependent on the available algorithms supported by the
version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
On recent releases of OpenSSL, `openssl list-message-digest-algorithms` will
display the available digest algorithms.
Example: generating the sha256 sum of a file
```... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
ec5aec3e-9acc-5306-9a03-2ea212899981 | docs | nodejs | nodejs_crypto | 7x | 47 | On recent releases of OpenSSL, `openssl list-message-digest-algorithms` will
display the available digest algorithms.
The `key` is the HMAC key used to generate the cryptographic HMAC hash.
Example: generating the sha256 HMAC of a file
```None
const filename = process.argv[2];
const crypto = require('crypto');
const... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
bccbd2aa-a23c-5565-bf20-4aaa9cdd5466 | docs | nodejs | nodejs_crypto | 7x | 48 | ### crypto.createVerify(algorithm)[#](#crypto_crypto_createverify_algorithm)
Added in: v0.1.92
Creates and returns a `Verify` object that uses the given algorithm.
Use [`crypto.getHashes()`](#crypto_crypto_gethashes) to obtain an array of names of the available
signing algorithms.
### crypto.getCiphers()[#](#crypto_... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
4983a537-2e30-5a16-9605-5d4222f5599f | docs | nodejs | nodejs_crypto | 7x | 49 | ### crypto.getDiffieHellman(group\_name)[#](#crypto_crypto_getdiffiehellman_group_name)
Added in: v0.7.5
Creates a predefined `DiffieHellman` key exchange object. The
supported groups are: `'modp1'`, `'modp2'`, `'modp5'` (defined in
[RFC 2412](https://www.rfc-editor.org/rfc/rfc2412.txt), but see [Caveats](#crypto_sup... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
09d27eb8-2821-53bb-aa2d-28fdaa6eace3 | docs | nodejs | nodejs_crypto | 7x | 50 | Example (obtaining a shared secret):
```None
const crypto = require('crypto');
const alice = crypto.getDiffieHellman('modp14');
const bob = crypto.getDiffieHellman('modp14');
alice.generateKeys();
bob.generateKeys();
const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
const bobSecret = bob.comp... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
676f9510-d9b5-5f5c-997d-f1a0e21eb94b | docs | nodejs | nodejs_crypto | 7x | 51 | | v6.0.0 | Calling this function without passing the `digest` parameter is deprecated now and will emit a warning. |
| v6.0.0 | The default encoding for `password` if it is a string changed from `binary` to `utf8`. |
| v0.5.5 | Added in: v0.5.5 |
Provides an asynchronous Password-Based Key Derivation Function 2 (PBKDF... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
473afc40-81ed-59ff-a7e3-48eaaa41f8eb | docs | nodejs | nodejs_crypto | 7x | 52 | salts are random and their lengths are greater than 16 bytes. See
[NIST SP 800-132](http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf) for details.
Example:
```None
const crypto = require('crypto');
crypto.pbkdf2('secret', 'salt', 100000, 512, 'sha512', (err, key) => {
if (err) throw err;
cons... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
3365d849-4185-5365-9533-f7b9939e35b1 | docs | nodejs | nodejs_crypto | 7x | 53 | implementation. A selected HMAC digest algorithm specified by `digest` is
applied to derive a key of the requested byte length (`keylen`) from the
`password`, `salt` and `iterations`.
If an error occurs an Error will be thrown, otherwise the derived key will be
returned as a [`Buffer`](buffer.html).
The `iterations` ... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
6399543e-4d3a-5d2c-a3e2-ff707b9cbd9d | docs | nodejs | nodejs_crypto | 7x | 54 | [`crypto.getHashes()`](#crypto_crypto_gethashes).
### crypto.privateDecrypt(private\_key, buffer)[#](#crypto_crypto_privatedecrypt_private_key_buffer)
Added in: v0.11.14
Decrypts `buffer` with `private_key`.
`private_key` can be an object or a string. If `private_key` is a string, it is
treated as the key with no p... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
578628d5-bdd3-5bbb-a512-5aba7700e952 | docs | nodejs | nodejs_crypto | 7x | 55 | ### crypto.privateEncrypt(private\_key, buffer)[#](#crypto_crypto_privateencrypt_private_key_buffer)
Added in: v1.1.0
Encrypts `buffer` with `private_key`.
`private_key` can be an object or a string. If `private_key` is a string, it is
treated as the key with no passphrase and will use `RSA_PKCS1_PADDING`.
If `priva... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
6e8575c3-7598-552b-bb44-cda67a4d91c9 | docs | nodejs | nodejs_crypto | 7x | 56 | ### crypto.publicDecrypt(public\_key, buffer)[#](#crypto_crypto_publicdecrypt_public_key_buffer)
Added in: v1.1.0
Decrypts `buffer` with `public_key`.
`public_key` can be an object or a string. If `public_key` is a string, it is
treated as the key with no passphrase and will use `RSA_PKCS1_PADDING`.
If `public_key` ... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
f2eecc0f-ce26-5993-a61e-53e26e5a4416 | docs | nodejs | nodejs_crypto | 7x | 57 | ### crypto.publicEncrypt(public\_key, buffer)[#](#crypto_crypto_publicencrypt_public_key_buffer)
Added in: v0.11.14
Encrypts `buffer` with `public_key`.
`public_key` can be an object or a string. If `public_key` is a string, it is
treated as the key with no passphrase and will use `RSA_PKCS1_OAEP_PADDING`.
If `publi... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
b9aaf4dd-75a8-573a-9532-40ffdbd0da6f | docs | nodejs | nodejs_crypto | 7x | 58 |
### crypto.randomBytes(size[, callback])[#](#crypto_crypto_randombytes_size_callback)
Added in: v0.5.8
Generates cryptographically strong pseudo-random data. The `size` argument
is a number indicating the number of bytes to generate.
If a `callback` function is provided, the bytes are generated asynchronously
and t... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
d4a5300c-8f51-5773-98c6-a1ece7124f93 | docs | nodejs | nodejs_crypto | 7x | 59 | `${buf.length} bytes of random data: ${buf.toString('hex')}`);
```
The `crypto.randomBytes()` method will block until there is sufficient entropy.
This should normally never take longer than a few milliseconds. The only time
when generating the random bytes may conceivably block for a longer period of
time is right ... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
55f275f1-147d-5765-bea6-dcf690f76d13 | docs | nodejs | nodejs_crypto | 7x | 60 | Synchronous version of [`crypto.randomFill()`](#crypto_crypto_randomfill_buffer_offset_size_callback).
Returns `buffer`
```None
const buf = Buffer.alloc(10);
console.log(crypto.randomFillSync(buf).toString('hex'));
crypto.randomFillSync(buf, 5);
console.log(buf.toString('hex'));
// The above is equivalent to the fo... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
647f1506-ef76-5aac-962e-7bb8862bc221 | docs | nodejs | nodejs_crypto | 7x | 61 | * `callback` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) `function(err, buf) {}`.
This function is similar to [`crypto.randomBytes()`](#crypto_crypto_randombytes_size_callback) but requires the first
argument to be a [`Buffer`](buffer.html) that will be fille... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
0dcd38d4-fe4e-5257-864f-5df529c82e7f | docs | nodejs | nodejs_crypto | 7x | 62 | ### crypto.setEngine(engine[, flags])[#](#crypto_crypto_setengine_engine_flags)
Added in: v0.11.11
Load and set the `engine` for some or all OpenSSL functions (selected by flags).
`engine` could be either an id or a path to the engine's shared library.
The optional `flags` argument uses `ENGINE_METHOD_ALL` by defau... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
495bcb5d-8ab6-5661-855c-04f8a72fe571 | docs | nodejs | nodejs_crypto | 7x | 63 | ### crypto.timingSafeEqual(a, b)[#](#crypto_crypto_timingsafeequal_a_b)
Added in: v6.6.0
Returns true if `a` is equal to `b`, without leaking timing information that
would allow an attacker to guess one of the values. This is suitable for
comparing HMAC digests or secret values like authentication cookies or
[capabil... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
01ffc617-a3fd-5b20-bcdb-fea75c999fdf | docs | nodejs | nodejs_crypto | 7x | 64 | typically found on other Node.js classes that implement the [streams](stream.html)
API (e.g. `update()`, `final()`, or `digest()`). Also, many methods accepted
and returned `'latin1'` encoded strings by default rather than Buffers. This
default was changed after Node.js v0.8 to use [`Buffer`](buffer.html) objects by de... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
c9ccf207-a34e-5a66-b325-011be38163fd | docs | nodejs | nodejs_crypto | 7x | 65 | The [`ecdh.setPublicKey()`](#crypto_ecdh_setpublickey_public_key_encoding) method is now deprecated as its inclusion in the
API is not useful. Either a previously stored private key should be set, which
automatically generates the associated public key, or [`ecdh.generateKeys()`](#crypto_ecdh_generatekeys_encoding_form... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
98eb9976-5fdc-5bb4-b568-aa18b1f869c6 | docs | nodejs | nodejs_crypto | 7x | 66 | Based on the recommendations of [NIST SP 800-131A](http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar1.pdf):
* MD5 and SHA-1 are no longer acceptable where collision resistance is
required such as digital signatures.
* The key used with RSA, DSA and DH algorithms is recommended to have
at least... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
a998228e-9fa3-5ca3-9768-fc5745011358 | docs | nodejs | nodejs_crypto | 7x | 67 | ### OpenSSL Options[#](#crypto_openssl_options)
| Constant | Description |
| --- | --- |
| `SSL_OP_ALL` | Applies multiple bug workarounds within OpenSSL. See <https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html> for detail. |
| `SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION` | Allows legacy insecure renegot... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
20b475df-7314-5252-8e6a-56e6ec6e7091 | docs | nodejs | nodejs_crypto | 7x | 68 | | `SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS` | Instructs OpenSSL to disable a SSL 3.0/TLS 1.0 vulnerability workaround added in OpenSSL 0.9.6d. |
| `SSL_OP_EPHEMERAL_RSA` | Instructs OpenSSL to always use the tmp\_rsa key when performing RSA operations. |
| `SSL_OP_LEGACY_SERVER_CONNECT` | Allows initial connection to server... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
80db58be-6715-50b2-8c38-42eb271f3a70 | docs | nodejs | nodejs_crypto | 7x | 69 | | `SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION` | Instructs OpenSSL to always start a new session when performing renegotiation. |
| `SSL_OP_NO_SSLv2` | Instructs OpenSSL to turn off SSL v2 |
| `SSL_OP_NO_SSLv3` | Instructs OpenSSL to turn off SSL v3 |
| `SSL_OP_NO_TICKET` | Instructs OpenSSL to disable use of RFC450... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
e8b40915-b0cc-51df-a1dd-9128d1dc035b | docs | nodejs | nodejs_crypto | 7x | 70 | | `SSL_OP_TLS_ROLLBACK_BUG` | Instructs OpenSSL to disable version rollback attack detection. |
### OpenSSL Engine Constants[#](#crypto_openssl_engine_constants)
| Constant | Description |
| --- | --- |
| `ENGINE_METHOD_RSA` | Limit engine usage to RSA |
| `ENGINE_METHOD_DSA` | Limit engine usage to DSA |
| `ENGINE_M... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
c01b891b-fbb1-51e2-a0ca-d02049a5699d | docs | nodejs | nodejs_crypto | 7x | 71 | ### Other OpenSSL Constants[#](#crypto_other_openssl_constants)
| Constant | Description |
| --- | --- |
| `DH_CHECK_P_NOT_SAFE_PRIME` | |
| `DH_CHECK_P_NOT_PRIME` | |
| `DH_UNABLE_TO_CHECK_GENERATOR` | |
| `DH_NOT_SUITABLE_GENERATOR` | |
| `NPN_ENABLED` | |
| `ALPN_ENABLED` | |
| `RSA_PKCS1_PADDING` | |
| `RSA... | large_dataset/raw/docs/nodejs/crypto/crypto_7x.md |
947f57ff-f289-5b42-b643-66f81e41bc6c | docs | nodejs | nodejs_crypto | 8x | 0 | # Crypto#
Source: https://nodejs.org/docs/latest-v8.x/api/crypto.html
Version: 8.x
[Stability: 2](documentation.html#documentation_stability_index) - Stable
The `crypto` module provides cryptographic functionality that includes a set of
wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
51306d9e-b795-5d98-b990-a06904d76bdb | docs | nodejs | nodejs_crypto | 8x | 1 | console.log('crypto support is disabled!');
}
```
## Class: Certificate[#](#crypto_class_certificate)
Added in: v0.11.8
SPKAC is a Certificate Signing Request mechanism originally implemented by
Netscape and was specified formally as part of [HTML5's `keygen` element](https://developer.mozilla.org/en-US/docs/Web/H... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
0a26473b-54c1-5d05-9fce-281f8eafd6ae | docs | nodejs | nodejs_crypto | 8x | 2 |
const cert1 = new crypto.Certificate();
const cert2 = crypto.Certificate();
```
### certificate.exportChallenge(spkac)[#](#crypto_certificate_exportchallenge_spkac)
Added in: v0.11.8
* `spkac` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [<Buffer>](buffer.html#bu... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
60b63dcb-a88a-5cce-8b06-9e79b153fe1b | docs | nodejs | nodejs_crypto | 8x | 3 | ### certificate.exportPublicKey(spkac)[#](#crypto_certificate_exportpublickey_spkac)
Added in: v0.11.8
* `spkac` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [<Buffer>](buffer.html#buffer_class_buffer) | [<TypedArray>](https://developer.mozilla.org/en-US/docs/Web/J... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
7a34259f-6f75-5a52-b1d8-e37274fe7e8a | docs | nodejs | nodejs_crypto | 8x | 4 | ### certificate.verifySpkac(spkac)[#](#crypto_certificate_verifyspkac_spkac)
Added in: v0.11.8
* `spkac` [<Buffer>](buffer.html#buffer_class_buffer) | [<TypedArray>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) | [<DataView>](https://developer.mozilla.org/en-US/docs/Web... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
2de72043-01b8-53c2-9ce6-6182829284cf | docs | nodejs | nodejs_crypto | 8x | 5 | data is written to produce encrypted data on the readable side, or
* Using the [`cipher.update()`](#crypto_cipher_update_data_inputencoding_outputencoding) and [`cipher.final()`](#crypto_cipher_final_outputencoding) methods to produce
the encrypted data.
The [`crypto.createCipher()`](#crypto_crypto_createcipher_al... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
89be484d-b922-59e8-b214-7aec147fe648 | docs | nodejs | nodejs_crypto | 8x | 6 | ```
Example: Using `Cipher` and piped streams:
```None
const crypto = require('crypto');
const fs = require('fs');
const cipher = crypto.createCipher('aes192', 'a password');
const input = fs.createReadStream('test.js');
const output = fs.createWriteStream('test.enc');
input.pipe(cipher).pipe(output);
```
Example:... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
13e319e0-2570-5dab-b9e6-4f2e8db8f13f | docs | nodejs | nodejs_crypto | 8x | 7 | * Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Any remaining enciphered contents.
If `outputEncoding` parameter is one of `'latin1'`, `'base64'` or `'hex'`,
a string is returned. If an `outputEncoding` is not p... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
5301a44c-c169-5422-aa2f-52a6756f5b51 | docs | nodejs | nodejs_crypto | 8x | 8 | The `cipher.setAAD()` method must be called before [`cipher.update()`](#crypto_cipher_update_data_inputencoding_outputencoding).
### cipher.getAuthTag()[#](#crypto_cipher_getauthtag)
Added in: v1.0.0
* Returns: [<Buffer>](buffer.html#buffer_class_buffer) When using an authenticated encryption mode (only `GCM` is
c... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
53961f04-318a-5437-84d2-821cd5c50acc | docs | nodejs | nodejs_crypto | 8x | 9 | When using block encryption algorithms, the `Cipher` class will automatically
add padding to the input data to the appropriate block size. To disable the
default padding call `cipher.setAutoPadding(false)`.
When `autoPadding` is `false`, the length of the entire input data must be a
multiple of the cipher's block size... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
679a4f7f-2ea1-5e7b-9bfc-fdb4260e4f26 | docs | nodejs | nodejs_crypto | 8x | 10 | * `data` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [<Buffer>](buffer.html#buffer_class_buffer) | [<TypedArray>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) | [<DataView>](https://developer.mozilla.org/en-US/docs/Web... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
932ab90f-c0f6-55e5-b8b9-86d215dd16f7 | docs | nodejs | nodejs_crypto | 8x | 11 | argument is not given, `data` must be a [`Buffer`](buffer.html), `TypedArray`, or
`DataView`. If `data` is a [`Buffer`](buffer.html), `TypedArray`, or `DataView`, then
`inputEncoding` is ignored.
The `outputEncoding` specifies the output format of the enciphered
data, and can be `'latin1'`, `'base64'` or `'hex'`. If t... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
e964601a-c51b-5905-8884-45cbfc3fc17c | docs | nodejs | nodejs_crypto | 8x | 12 | data is written to produce unencrypted data on the readable side, or
* Using the [`decipher.update()`](#crypto_decipher_update_data_inputencoding_outputencoding) and [`decipher.final()`](#crypto_decipher_final_outputencoding) methods to
produce the unencrypted data.
The [`crypto.createDecipher()`](#crypto_crypto_c... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
7f268de9-a1fa-5a96-95fc-bcd56e957dc7 | docs | nodejs | nodejs_crypto | 8x | 13 | 'ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504';
decipher.write(encrypted, 'hex');
decipher.end();
```
Example: Using `Decipher` and piped streams:
```None
const crypto = require('crypto');
const fs = require('fs');
const decipher = crypto.createDecipher('aes192', 'a password');
const input = ... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
0f2faea1-ac25-5372-805a-dbcdfd59760f | docs | nodejs | nodejs_crypto | 8x | 14 | ### decipher.final([outputEncoding])[#](#crypto_decipher_final_outputencoding)
Added in: v0.1.94
* `outputEncoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-US/do... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
25210d86-2e75-5d01-9e5c-304497ea9de6 | docs | nodejs | nodejs_crypto | 8x | 15 | * `buffer` [<Buffer>](buffer.html#buffer_class_buffer) | [<TypedArray>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) | [<DataView>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
* Returns: [<Cipher>](crypto.html#crypto_class_ci... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
9518644b-25b8-58b2-a232-5f2578dd4183 | docs | nodejs | nodejs_crypto | 8x | 16 | * `buffer` [<Buffer>](buffer.html#buffer_class_buffer) | [<TypedArray>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) | [<DataView>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
* Returns: [<Cipher>](crypto.html#crypto_class_ci... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
ba35b8a4-79af-508e-b3a8-9ca73c5c8b92 | docs | nodejs | nodejs_crypto | 8x | 17 | arbitrarily short authentication tag to increase the chances of successfully
passing authentication (up to 0.39%). It is highly recommended to associate one
of the values 16, 15, 14, 13, 12, 8 or 4 bytes with each key, and to only permit
authentication tags of that length, see [NIST SP 800-38D](http://nvlpubs.nist.gov/... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
cfdc566c-9381-57de-9eb9-78e39cac7dce | docs | nodejs | nodejs_crypto | 8x | 18 | [`decipher.final()`](#crypto_decipher_final_outputencoding) from checking for and removing padding.
Turning auto padding off will only work if the input data's length is a
multiple of the ciphers block size.
The `decipher.setAutoPadding()` method must be called before
[`decipher.final()`](#crypto_decipher_final_outpu... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
7fdf8c2c-5c05-579d-817b-6c5476f73777 | docs | nodejs | nodejs_crypto | 8x | 19 | * `inputEncoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* `outputEncoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozil... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
be19f9ed-23c6-58b0-bcdb-d469e182ccbd | docs | nodejs | nodejs_crypto | 8x | 20 | `outputEncoding` is provided, a [`Buffer`](buffer.html) is returned.
The `decipher.update()` method can be called multiple times with new data until
[`decipher.final()`](#crypto_decipher_final_outputencoding) is called. Calling `decipher.update()` after
[`decipher.final()`](#crypto_decipher_final_outputencoding) will ... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
879d3a84-39e7-5d9f-9a68-934b179c6ad6 | docs | nodejs | nodejs_crypto | 8x | 21 | const bobKey = bob.generateKeys();
// Exchange and generate the secret...
const aliceSecret = alice.computeSecret(bobKey);
const bobSecret = bob.computeSecret(aliceKey);
// OK
assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
```
### diffieHellman.computeSecret(otherPublicKey[, inputEncodin... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
02d929a9-f828-536c-afb4-1622a5fb4ba1 | docs | nodejs | nodejs_crypto | 8x | 22 | * `outputEncoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
Computes the shared secret using `otherPublicKey` a... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
582cc7f2-5c60-5782-b04f-1d5838b4e01b | docs | nodejs | nodejs_crypto | 8x | 23 | ### diffieHellman.generateKeys([encoding])[#](#crypto_diffiehellman_generatekeys_encoding)
Added in: v0.5.0
* `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
9401f294-fbba-5730-bf1f-dbc353503a62 | docs | nodejs | nodejs_crypto | 8x | 24 | * Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
Returns the Diffie-Hellman generator in the specified `encoding`, which can
be `'latin1'`, `'hex'`, or `'base64'`. If `encoding` is provided a string is
returned; oth... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
c4e085a8-feb0-52ec-af00-7a03ea5d809e | docs | nodejs | nodejs_crypto | 8x | 25 | ### diffieHellman.getPrivateKey([encoding])[#](#crypto_diffiehellman_getprivatekey_encoding)
Added in: v0.5.0
* `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/e... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
6e4ddff9-8179-5b3d-916d-20857224be15 | docs | nodejs | nodejs_crypto | 8x | 26 | Returns the Diffie-Hellman public key in the specified `encoding`, which
can be `'latin1'`, `'hex'`, or `'base64'`. If `encoding` is provided a
string is returned; otherwise a [`Buffer`](buffer.html) is returned.
### diffieHellman.setPrivateKey(privateKey[, encoding])[#](#crypto_diffiehellman_setprivatekey_privatekey_... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
ab78533b-332b-54a1-884a-84b89d4e2de5 | docs | nodejs | nodejs_crypto | 8x | 27 | to be a string. If no `encoding` is provided, `privateKey` is expected
to be a [`Buffer`](buffer.html), `TypedArray`, or `DataView`.
### diffieHellman.setPublicKey(publicKey[, encoding])[#](#crypto_diffiehellman_setpublickey_publickey_encoding)
Added in: v0.5.0
* `publicKey` [<string>](https://developer.mozilla.org/... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
32a533ae-8f35-5a7a-81b4-6afefa78e186 | docs | nodejs | nodejs_crypto | 8x | 28 | to be a [`Buffer`](buffer.html), `TypedArray`, or `DataView`.
### diffieHellman.verifyError[#](#crypto_diffiehellman_verifyerror)
Added in: v0.11.12
A bit field containing any warnings and/or errors resulting from a check
performed during initialization of the `DiffieHellman` object.
The following values are valid ... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
08456f32-aed9-54e5-a53a-92cdc86397ae | docs | nodejs | nodejs_crypto | 8x | 29 | const bob = crypto.createECDH('secp521r1');
const bobKey = bob.generateKeys();
// Exchange and generate the secret...
const aliceSecret = alice.computeSecret(bobKey);
const bobSecret = bob.computeSecret(aliceKey);
assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
// OK
```
### ecdh.computeS... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
11856c96-90dc-5d63-a35a-b998dc5ad41b | docs | nodejs | nodejs_crypto | 8x | 30 | * `inputEncoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* `outputEncoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozil... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
091fbf02-acba-511b-86e7-dff3361ebaa0 | docs | nodejs | nodejs_crypto | 8x | 31 | ### ecdh.generateKeys([encoding[, format]])[#](#crypto_ecdh_generatekeys_encoding_format)
Added in: v0.11.14
* `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* `format` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
76828e1b-f70c-50f2-b78e-051b0aec3272 | docs | nodejs | nodejs_crypto | 8x | 32 | is returned.
### ecdh.getPrivateKey([encoding])[#](#crypto_ecdh_getprivatekey_encoding)
Added in: v0.11.14
* `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
4f815a5c-a2ea-53da-8b1d-9957ce1e1f93 | docs | nodejs | nodejs_crypto | 8x | 33 | * Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The EC Diffie-Hellman public key in the specified
`encoding` and `format`.
The `format` argument specifies point encoding and can be `'compressed'` or
`'uncompresse... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
7152888e-7f9d-5cb2-9f6e-bfacb307bc33 | docs | nodejs | nodejs_crypto | 8x | 34 | * `privateKey` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [<Buffer>](buffer.html#buffer_class_buffer) | [<TypedArray>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) | [<DataView>](https://developer.mozilla.org/en-US/do... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
73a6a07d-6ad9-59eb-8f4a-7fc0afd43f79 | docs | nodejs | nodejs_crypto | 8x | 35 | ### ecdh.setPublicKey(publicKey[, encoding])[#](#crypto_ecdh_setpublickey_publickey_encoding)
Added in: v0.11.14Deprecated since: v5.2.0
[Stability: 0](documentation.html#documentation_stability_index) - Deprecated
* `publicKey` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Strin... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
5eb69848-997f-51e2-900c-e89ad64179ba | docs | nodejs | nodejs_crypto | 8x | 36 | only requires a private key and the other party's public key to compute the
shared secret. Typically either [`ecdh.generateKeys()`](#crypto_ecdh_generatekeys_encoding_format) or
[`ecdh.setPrivateKey()`](#crypto_ecdh_setprivatekey_privatekey_encoding) will be called. The [`ecdh.setPrivateKey()`](#crypto_ecdh_setprivatek... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
c6f85bb3-e105-53d5-9746-058c02a73c81 | docs | nodejs | nodejs_crypto | 8x | 37 | const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
const bobSecret = bob.computeSecret(alice.getPublicKey(), null, 'hex');
// aliceSecret and bobSecret should be the same shared secret value
console.log(aliceSecret === bobSecret);
```
## Class: Hash[#](#crypto_class_hash)
Added in: v0.1.92
Th... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
ede09da0-bf7e-5c27-8e84-e2a0c9d871be | docs | nodejs | nodejs_crypto | 8x | 38 | const hash = crypto.createHash('sha256');
hash.on('readable', () => {
const data = hash.read();
if (data) {
console.log(data.toString('hex'));
// Prints:
// 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
}
});
hash.write('some data to hash');
hash.end();
```
Example: Using `Hash... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
3c8dfa71-bca4-5df1-bfcc-52627bd14dd2 | docs | nodejs | nodejs_crypto | 8x | 39 | ### hash.digest([encoding])[#](#crypto_hash_digest_encoding)
Added in: v0.1.92
* `encoding` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_s... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
381106fc-32b6-5aa6-8952-16c76bbb2dbf | docs | nodejs | nodejs_crypto | 8x | 40 | * `data` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [<Buffer>](buffer.html#buffer_class_buffer) | [<TypedArray>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) | [<DataView>](https://developer.mozilla.org/en-US/docs/Web... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
6d9cd637-564c-5d8d-b1a0-eae54e1c1eb9 | docs | nodejs | nodejs_crypto | 8x | 41 | ## Class: Hmac[#](#crypto_class_hmac)
Added in: v0.1.94
The `Hmac` Class is a utility for creating cryptographic HMAC digests. It can
be used in one of two ways:
* As a [stream](stream.html) that is both readable and writable, where data is written
to produce a computed HMAC digest on the readable side, or
* Using... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
e7ae613f-64ad-5536-9505-518bb1a05a19 | docs | nodejs | nodejs_crypto | 8x | 42 | hmac.write('some data to hash');
hmac.end();
```
Example: Using `Hmac` and piped streams:
```None
const crypto = require('crypto');
const fs = require('fs');
const hmac = crypto.createHmac('sha256', 'a secret');
const input = fs.createReadStream('test.js');
input.pipe(hmac).pipe(process.stdout);
```
Example: Using ... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
82c96f3f-12a4-5df8-8622-b6ee6c276576 | docs | nodejs | nodejs_crypto | 8x | 43 | * Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
Calculates the HMAC digest of all of the data passed using [`hmac.update()`](#crypto_hmac_update_data_inputencoding).
The `encoding` can be `'hex'`, `'latin1'` or `'b... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
57204a23-ebeb-5c3b-a649-0d3d8779f069 | docs | nodejs | nodejs_crypto | 8x | 44 | * `data` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [<Buffer>](buffer.html#buffer_class_buffer) | [<TypedArray>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) | [<DataView>](https://developer.mozilla.org/en-US/docs/Web... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
59b73e9c-ea69-5c58-b30d-240580713fcf | docs | nodejs | nodejs_crypto | 8x | 45 | ## Class: Sign[#](#crypto_class_sign)
Added in: v0.1.92
The `Sign` Class is a utility for generating signatures. It can be used in one
of two ways:
* As a writable [stream](stream.html), where data to be signed is written and the
[`sign.sign()`](#crypto_sign_sign_privatekey_outputformat) method is used to generate... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
f5f7d7fd-f466-50c7-af36-52ce3a30631d | docs | nodejs | nodejs_crypto | 8x | 46 | console.log(sign.sign(privateKey, 'hex'));
// Prints: the calculated signature using the specified private key and
// SHA-256. For RSA keys, the algorithm is RSASSA-PKCS1-v1_5 (see padding
// parameter below for RSASSA-PSS). For EC keys, the algorithm is ECDSA.
```
Example: Using the [`sign.update()`](#crypto_sign_upd... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
0d5cd841-c1d7-5e50-ae6f-4a169765fa53 | docs | nodejs | nodejs_crypto | 8x | 47 | const crypto = require('crypto');
const sign = crypto.createSign('RSA-SHA256');
sign.update('some data to sign');
const privateKey = getPrivateKeySomehow();
console.log(sign.sign(privateKey, 'hex'));
// Prints: the calculated signature
```
### sign.sign(privateKey[, outputFormat])[#](#crypto_sign_sign_privatekey_out... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
ae99a916-3689-5726-9e8d-44e885430a3b | docs | nodejs | nodejs_crypto | 8x | 48 | * Returns: [<Buffer>](buffer.html#buffer_class_buffer) | [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
Calculates the signature on all the data passed through using either
[`sign.update()`](#crypto_sign_update_data_inputencoding) or [`sign.write()`](stream.html#stream_... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
2a82b691-1881-556f-8469-2a5acc20bcf6 | docs | nodejs | nodejs_crypto | 8x | 49 | * `padding`: [<integer>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) - Optional padding value for RSA, one of the following:
+ `crypto.constants.RSA_PKCS1_PADDING` (default)
+ `crypto.constants.RSA_PKCS1_PSS_PADDING`
Note that `RSA_PKCS1_PSS_PADDING` will use MGF1 with t... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
1b015837-095f-568e-a663-bd6f00dfeea1 | docs | nodejs | nodejs_crypto | 8x | 50 | The `Sign` object can not be again used after `sign.sign()` method has been
called. Multiple calls to `sign.sign()` will result in an error being thrown.
### sign.update(data[, inputEncoding])[#](#crypto_sign_update_data_inputencoding)
History
| Version | Changes |
| --- | --- |
| v6.0.0 | The default `inputEncoding... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
1c58798b-3fe7-5715-98d1-fb5d4e13f41e | docs | nodejs | nodejs_crypto | 8x | 51 | `'latin1'`. If `encoding` is not provided, and the `data` is a string, an
encoding of `'utf8'` is enforced. If `data` is a [`Buffer`](buffer.html), `TypedArray`, or
`DataView`, then `inputEncoding` is ignored.
This can be called many times with new data as it is streamed.
## Class: Verify[#](#crypto_class_verify)
Ad... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
100070bd-dbe5-56df-92a0-b1067aa6d378 | docs | nodejs | nodejs_crypto | 8x | 52 | const verify = crypto.createVerify('SHA256');
verify.write('some data to sign');
verify.end();
const publicKey = getPublicKeySomehow();
const signature = getSignatureToVerify();
console.log(verify.verify(publicKey, signature));
// Prints: true or false
```
Example: Using the [`verify.update()`](#crypto_verify_update... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
5982fe52-f314-580a-a691-56d4c5f426b2 | docs | nodejs | nodejs_crypto | 8x | 53 | * `data` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [<Buffer>](buffer.html#buffer_class_buffer) | [<TypedArray>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) | [<DataView>](https://developer.mozilla.org/en-US/docs/Web... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
660e76c8-d146-5083-9a75-fa115bc73f4b | docs | nodejs | nodejs_crypto | 8x | 54 | ### verify.verify(object, signature[, signatureFormat])[#](#crypto_verify_verify_object_signature_signatureformat)
History
| Version | Changes |
| --- | --- |
| v8.0.0 | Support for RSASSA-PSS and additional options was added. |
| v0.1.92 | Added in: v0.1.92 |
* `object` [<string>](https://developer.mozilla.org/en-U... | large_dataset/raw/docs/nodejs/crypto/crypto_8x.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.