5 Use `require('crypto')` to access this module.
7 The crypto module offers a way of encapsulating secure credentials to be
8 used as part of a secure HTTPS net or http connection.
10 It also offers a set of wrappers for OpenSSL's hash, hmac, cipher,
11 decipher, sign and verify methods.
14 ## crypto.setEngine(engine[, flags])
16 Load and set engine for some/all OpenSSL functions (selected by flags).
18 `engine` could be either an id or a path to the engine's shared library.
20 `flags` is optional and has `ENGINE_METHOD_ALL` value by default. It could take
21 one of or mix of following flags (defined in `constants` module):
26 * `ENGINE_METHOD_RAND`
27 * `ENGINE_METHOD_ECDH`
28 * `ENGINE_METHOD_ECDSA`
29 * `ENGINE_METHOD_CIPHERS`
30 * `ENGINE_METHOD_DIGESTS`
31 * `ENGINE_METHOD_STORE`
32 * `ENGINE_METHOD_PKEY_METH`
33 * `ENGINE_METHOD_PKEY_ASN1_METH`
35 * `ENGINE_METHOD_NONE`
38 ## crypto.getCiphers()
40 Returns an array with the names of the supported ciphers.
44 var ciphers = crypto.getCiphers();
45 console.log(ciphers); // ['AES-128-CBC', 'AES-128-CBC-HMAC-SHA1', ...]
50 Returns an array with the names of the supported hash algorithms.
54 var hashes = crypto.getHashes();
55 console.log(hashes); // ['sha', 'sha1', 'sha1WithRSAEncryption', ...]
58 ## crypto.createCredentials(details)
60 Stability: 0 - Deprecated. Use [tls.createSecureContext][] instead.
62 Creates a credentials object, with the optional details being a
65 * `pfx` : A string or buffer holding the PFX or PKCS12 encoded private
66 key, certificate and CA certificates
67 * `key` : A string holding the PEM encoded private key
68 * `passphrase` : A string of passphrase for the private key or pfx
69 * `cert` : A string holding the PEM encoded certificate
70 * `ca` : Either a string or list of strings of PEM encoded CA
71 certificates to trust.
72 * `crl` : Either a string or list of strings of PEM encoded CRLs
73 (Certificate Revocation List)
74 * `ciphers`: A string describing the ciphers to use or exclude.
76 <http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT>
77 for details on the format.
79 If no 'ca' details are given, then io.js will use the default
80 publicly trusted list of CAs as given in
81 <http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt>.
84 ## crypto.createHash(algorithm)
86 Creates and returns a hash object, a cryptographic hash with the given
87 algorithm which can be used to generate hash digests.
89 `algorithm` is dependent on the available algorithms supported by the
90 version of OpenSSL on the platform. Examples are `'sha1'`, `'md5'`,
91 `'sha256'`, `'sha512'`, etc. On recent releases, `openssl
92 list-message-digest-algorithms` will display the available digest
95 Example: this program that takes the sha1 sum of a file
97 var filename = process.argv[2];
98 var crypto = require('crypto');
99 var fs = require('fs');
101 var shasum = crypto.createHash('sha1');
103 var s = fs.ReadStream(filename);
104 s.on('data', function(d) {
108 s.on('end', function() {
109 var d = shasum.digest('hex');
110 console.log(d + ' ' + filename);
115 The class for creating hash digests of data.
117 It is a [stream](stream.html) that is both readable and writable. The
118 written data is used to compute the hash. Once the writable side of
119 the stream is ended, use the `read()` method to get the computed hash
120 digest. The legacy `update` and `digest` methods are also supported.
122 Returned by `crypto.createHash`.
124 ### hash.update(data[, input_encoding])
126 Updates the hash content with the given `data`, the encoding of which
127 is given in `input_encoding` and can be `'utf8'`, `'ascii'` or
128 `'binary'`. If no encoding is provided and the input is a string an
129 encoding of `'binary'` is enforced. If `data` is a `Buffer` then
130 `input_encoding` is ignored.
132 This can be called many times with new data as it is streamed.
134 ### hash.digest([encoding])
136 Calculates the digest of all of the passed data to be hashed. The
137 `encoding` can be `'hex'`, `'binary'` or `'base64'`. If no encoding
138 is provided, then a buffer is returned.
140 Note: `hash` object can not be used after `digest()` method has been
144 ## crypto.createHmac(algorithm, key)
146 Creates and returns a hmac object, a cryptographic hmac with the given
149 It is a [stream](stream.html) that is both readable and writable. The
150 written data is used to compute the hmac. Once the writable side of
151 the stream is ended, use the `read()` method to get the computed
152 digest. The legacy `update` and `digest` methods are also supported.
154 `algorithm` is dependent on the available algorithms supported by
155 OpenSSL - see createHash above. `key` is the hmac key to be used.
159 Class for creating cryptographic hmac content.
161 Returned by `crypto.createHmac`.
163 ### hmac.update(data)
165 Update the hmac content with the given `data`. This can be called
166 many times with new data as it is streamed.
168 ### hmac.digest([encoding])
170 Calculates the digest of all of the passed data to the hmac. The
171 `encoding` can be `'hex'`, `'binary'` or `'base64'`. If no encoding
172 is provided, then a buffer is returned.
174 Note: `hmac` object can not be used after `digest()` method has been
178 ## crypto.createCipher(algorithm, password)
180 Creates and returns a cipher object, with the given algorithm and
183 `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
184 recent releases, `openssl list-cipher-algorithms` will display the
185 available cipher algorithms. `password` is used to derive key and IV,
186 which must be a `'binary'` encoded string or a [buffer](buffer.html).
188 It is a [stream](stream.html) that is both readable and writable. The
189 written data is used to compute the hash. Once the writable side of
190 the stream is ended, use the `read()` method to get the enciphered
191 contents. The legacy `update` and `final` methods are also supported.
193 Note: `createCipher` derives keys with the OpenSSL function [EVP_BytesToKey][]
194 with the digest algorithm set to MD5, one iteration, and no salt. The lack of
195 salt allows dictionary attacks as the same password always creates the same key.
196 The low iteration count and non-cryptographically secure hash algorithm allow
197 passwords to be tested very rapidly.
199 In line with OpenSSL's recommendation to use pbkdf2 instead of EVP_BytesToKey it
200 is recommended you derive a key and iv yourself with [crypto.pbkdf2][] and to
201 then use [createCipheriv()][] to create the cipher stream.
203 ## crypto.createCipheriv(algorithm, key, iv)
205 Creates and returns a cipher object, with the given algorithm, key and
208 `algorithm` is the same as the argument to `createCipher()`. `key` is
209 the raw key used by the algorithm. `iv` is an [initialization
210 vector](http://en.wikipedia.org/wiki/Initialization_vector).
212 `key` and `iv` must be `'binary'` encoded strings or
213 [buffers](buffer.html).
217 Class for encrypting data.
219 Returned by `crypto.createCipher` and `crypto.createCipheriv`.
221 Cipher objects are [streams](stream.html) that are both readable and
222 writable. The written plain text data is used to produce the
223 encrypted data on the readable side. The legacy `update` and `final`
224 methods are also supported.
226 ### cipher.update(data[, input_encoding][, output_encoding])
228 Updates the cipher with `data`, the encoding of which is given in
229 `input_encoding` and can be `'utf8'`, `'ascii'` or `'binary'`. If no
230 encoding is provided, then a buffer is expected.
231 If `data` is a `Buffer` then `input_encoding` is ignored.
233 The `output_encoding` specifies the output format of the enciphered
234 data, and can be `'binary'`, `'base64'` or `'hex'`. If no encoding is
235 provided, then a buffer is returned.
237 Returns the enciphered contents, and can be called many times with new
238 data as it is streamed.
240 ### cipher.final([output_encoding])
242 Returns any remaining enciphered contents, with `output_encoding`
243 being one of: `'binary'`, `'base64'` or `'hex'`. If no encoding is
244 provided, then a buffer is returned.
246 Note: `cipher` object can not be used after `final()` method has been
249 ### cipher.setAutoPadding(auto_padding=true)
251 You can disable automatic padding of the input data to block size. If
252 `auto_padding` is false, the length of the entire input data must be a
253 multiple of the cipher's block size or `final` will fail. Useful for
254 non-standard padding, e.g. using `0x0` instead of PKCS padding. You
255 must call this before `cipher.final`.
257 ### cipher.getAuthTag()
259 For authenticated encryption modes (currently supported: GCM), this
260 method returns a `Buffer` that represents the _authentication tag_ that
261 has been computed from the given data. Should be called after
262 encryption has been completed using the `final` method!
264 ### cipher.setAAD(buffer)
266 For authenticated encryption modes (currently supported: GCM), this
267 method sets the value used for the additional authenticated data (AAD) input
271 ## crypto.createDecipher(algorithm, password)
273 Creates and returns a decipher object, with the given algorithm and
274 key. This is the mirror of the [createCipher()][] above.
276 ## crypto.createDecipheriv(algorithm, key, iv)
278 Creates and returns a decipher object, with the given algorithm, key
279 and iv. This is the mirror of the [createCipheriv()][] above.
283 Class for decrypting data.
285 Returned by `crypto.createDecipher` and `crypto.createDecipheriv`.
287 Decipher objects are [streams](stream.html) that are both readable and
288 writable. The written enciphered data is used to produce the
289 plain-text data on the the readable side. The legacy `update` and
290 `final` methods are also supported.
292 ### decipher.update(data[, input_encoding][, output_encoding])
294 Updates the decipher with `data`, which is encoded in `'binary'`,
295 `'base64'` or `'hex'`. If no encoding is provided, then a buffer is
297 If `data` is a `Buffer` then `input_encoding` is ignored.
299 The `output_decoding` specifies in what format to return the
300 deciphered plaintext: `'binary'`, `'ascii'` or `'utf8'`. If no
301 encoding is provided, then a buffer is returned.
303 ### decipher.final([output_encoding])
305 Returns any remaining plaintext which is deciphered, with
306 `output_encoding` being one of: `'binary'`, `'ascii'` or `'utf8'`. If
307 no encoding is provided, then a buffer is returned.
309 Note: `decipher` object can not be used after `final()` method has been
312 ### decipher.setAutoPadding(auto_padding=true)
314 You can disable auto padding if the data has been encrypted without
315 standard block padding to prevent `decipher.final` from checking and
316 removing it. Can only work if the input data's length is a multiple of
317 the ciphers block size. You must call this before streaming data to
320 ### decipher.setAuthTag(buffer)
322 For authenticated encryption modes (currently supported: GCM), this
323 method must be used to pass in the received _authentication tag_.
324 If no tag is provided or if the ciphertext has been tampered with,
325 `final` will throw, thus indicating that the ciphertext should
326 be discarded due to failed authentication.
328 ### decipher.setAAD(buffer)
330 For authenticated encryption modes (currently supported: GCM), this
331 method sets the value used for the additional authenticated data (AAD) input
335 ## crypto.createSign(algorithm)
337 Creates and returns a signing object, with the given algorithm. On
338 recent OpenSSL releases, `openssl list-public-key-algorithms` will
339 display the available signing algorithms. Examples are `'RSA-SHA256'`.
343 Class for generating signatures.
345 Returned by `crypto.createSign`.
347 Sign objects are writable [streams](stream.html). The written data is
348 used to generate the signature. Once all of the data has been
349 written, the `sign` method will return the signature. The legacy
350 `update` method is also supported.
352 ### sign.update(data)
354 Updates the sign object with data. This can be called many times
355 with new data as it is streamed.
357 ### sign.sign(private_key[, output_format])
359 Calculates the signature on all the updated data passed through the
362 `private_key` can be an object or a string. If `private_key` is a string, it is
363 treated as the key with no passphrase.
367 * `key` : A string holding the PEM encoded private key
368 * `passphrase` : A string of passphrase for the private key
370 Returns the signature in `output_format` which can be `'binary'`,
371 `'hex'` or `'base64'`. If no encoding is provided, then a buffer is
374 Note: `sign` object can not be used after `sign()` method has been
377 ## crypto.createVerify(algorithm)
379 Creates and returns a verification object, with the given algorithm.
380 This is the mirror of the signing object above.
384 Class for verifying signatures.
386 Returned by `crypto.createVerify`.
388 Verify objects are writable [streams](stream.html). The written data
389 is used to validate against the supplied signature. Once all of the
390 data has been written, the `verify` method will return true if the
391 supplied signature is valid. The legacy `update` method is also
394 ### verifier.update(data)
396 Updates the verifier object with data. This can be called many times
397 with new data as it is streamed.
399 ### verifier.verify(object, signature[, signature_format])
401 Verifies the signed data by using the `object` and `signature`.
402 `object` is a string containing a PEM encoded object, which can be
403 one of RSA public key, DSA public key, or X.509 certificate.
404 `signature` is the previously calculated signature for the data, in
405 the `signature_format` which can be `'binary'`, `'hex'` or `'base64'`.
406 If no encoding is specified, then a buffer is expected.
408 Returns true or false depending on the validity of the signature for
409 the data and public key.
411 Note: `verifier` object can not be used after `verify()` method has been
414 ## crypto.createDiffieHellman(prime_length[, generator])
416 Creates a Diffie-Hellman key exchange object and generates a prime of
417 `prime_length` bits and using an optional specific numeric `generator`.
418 If no `generator` is specified, then `2` is used.
420 ## crypto.createDiffieHellman(prime[, prime_encoding][, generator][, generator_encoding])
422 Creates a Diffie-Hellman key exchange object using the supplied `prime` and an
423 optional specific `generator`.
424 `generator` can be a number, string, or Buffer.
425 If no `generator` is specified, then `2` is used.
426 `prime_encoding` and `generator_encoding` can be `'binary'`, `'hex'`, or `'base64'`.
427 If no `prime_encoding` is specified, then a Buffer is expected for `prime`.
428 If no `generator_encoding` is specified, then a Buffer is expected for `generator`.
430 ## Class: DiffieHellman
432 The class for creating Diffie-Hellman key exchanges.
434 Returned by `crypto.createDiffieHellman`.
436 ### diffieHellman.verifyError
438 A bit field containing any warnings and/or errors as a result of a check performed
439 during initialization. The following values are valid for this property
440 (defined in `constants` module):
442 * `DH_CHECK_P_NOT_SAFE_PRIME`
443 * `DH_CHECK_P_NOT_PRIME`
444 * `DH_UNABLE_TO_CHECK_GENERATOR`
445 * `DH_NOT_SUITABLE_GENERATOR`
447 ### diffieHellman.generateKeys([encoding])
449 Generates private and public Diffie-Hellman key values, and returns
450 the public key in the specified encoding. This key should be
451 transferred to the other party. Encoding can be `'binary'`, `'hex'`,
452 or `'base64'`. If no encoding is provided, then a buffer is returned.
454 ### diffieHellman.computeSecret(other_public_key[, input_encoding][, output_encoding])
456 Computes the shared secret using `other_public_key` as the other
457 party's public key and returns the computed shared secret. Supplied
458 key is interpreted using specified `input_encoding`, and secret is
459 encoded using specified `output_encoding`. Encodings can be
460 `'binary'`, `'hex'`, or `'base64'`. If the input encoding is not
461 provided, then a buffer is expected.
463 If no output encoding is given, then a buffer is returned.
465 ### diffieHellman.getPrime([encoding])
467 Returns the Diffie-Hellman prime in the specified encoding, which can
468 be `'binary'`, `'hex'`, or `'base64'`. If no encoding is provided,
469 then a buffer is returned.
471 ### diffieHellman.getGenerator([encoding])
473 Returns the Diffie-Hellman generator in the specified encoding, which can
474 be `'binary'`, `'hex'`, or `'base64'`. If no encoding is provided,
475 then a buffer is returned.
477 ### diffieHellman.getPublicKey([encoding])
479 Returns the Diffie-Hellman public key in the specified encoding, which
480 can be `'binary'`, `'hex'`, or `'base64'`. If no encoding is provided,
481 then a buffer is returned.
483 ### diffieHellman.getPrivateKey([encoding])
485 Returns the Diffie-Hellman private key in the specified encoding,
486 which can be `'binary'`, `'hex'`, or `'base64'`. If no encoding is
487 provided, then a buffer is returned.
489 ### diffieHellman.setPublicKey(public_key[, encoding])
491 Sets the Diffie-Hellman public key. Key encoding can be `'binary'`,
492 `'hex'` or `'base64'`. If no encoding is provided, then a buffer is
495 ### diffieHellman.setPrivateKey(private_key[, encoding])
497 Sets the Diffie-Hellman private key. Key encoding can be `'binary'`,
498 `'hex'` or `'base64'`. If no encoding is provided, then a buffer is
501 ## crypto.getDiffieHellman(group_name)
503 Creates a predefined Diffie-Hellman key exchange object. The
504 supported groups are: `'modp1'`, `'modp2'`, `'modp5'` (defined in [RFC
505 2412][]) and `'modp14'`, `'modp15'`, `'modp16'`, `'modp17'`,
506 `'modp18'` (defined in [RFC 3526][]). The returned object mimics the
507 interface of objects created by [crypto.createDiffieHellman()][]
508 above, but will not allow to change the keys (with
509 [diffieHellman.setPublicKey()][] for example). The advantage of using
510 this routine is that the parties don't have to generate nor exchange
511 group modulus beforehand, saving both processor and communication
514 Example (obtaining a shared secret):
516 var crypto = require('crypto');
517 var alice = crypto.getDiffieHellman('modp5');
518 var bob = crypto.getDiffieHellman('modp5');
520 alice.generateKeys();
523 var alice_secret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
524 var bob_secret = bob.computeSecret(alice.getPublicKey(), null, 'hex');
526 /* alice_secret and bob_secret should be the same */
527 console.log(alice_secret == bob_secret);
529 ## crypto.createECDH(curve_name)
531 Creates a Elliptic Curve (EC) Diffie-Hellman key exchange object using a
532 predefined curve specified by `curve_name` string.
536 The class for creating EC Diffie-Hellman key exchanges.
538 Returned by `crypto.createECDH`.
540 ### ECDH.generateKeys([encoding[, format]])
542 Generates private and public EC Diffie-Hellman key values, and returns
543 the public key in the specified format and encoding. This key should be
544 transferred to the other party.
546 Format specifies point encoding and can be `'compressed'`, `'uncompressed'`, or
547 `'hybrid'`. If no format is provided - the point will be returned in
548 `'uncompressed'` format.
550 Encoding can be `'binary'`, `'hex'`, or `'base64'`. If no encoding is provided,
551 then a buffer is returned.
553 ### ECDH.computeSecret(other_public_key[, input_encoding][, output_encoding])
555 Computes the shared secret using `other_public_key` as the other
556 party's public key and returns the computed shared secret. Supplied
557 key is interpreted using specified `input_encoding`, and secret is
558 encoded using specified `output_encoding`. Encodings can be
559 `'binary'`, `'hex'`, or `'base64'`. If the input encoding is not
560 provided, then a buffer is expected.
562 If no output encoding is given, then a buffer is returned.
564 ### ECDH.getPublicKey([encoding[, format]])
566 Returns the EC Diffie-Hellman public key in the specified encoding and format.
568 Format specifies point encoding and can be `'compressed'`, `'uncompressed'`, or
569 `'hybrid'`. If no format is provided - the point will be returned in
570 `'uncompressed'` format.
572 Encoding can be `'binary'`, `'hex'`, or `'base64'`. If no encoding is provided,
573 then a buffer is returned.
575 ### ECDH.getPrivateKey([encoding])
577 Returns the EC Diffie-Hellman private key in the specified encoding,
578 which can be `'binary'`, `'hex'`, or `'base64'`. If no encoding is
579 provided, then a buffer is returned.
581 ### ECDH.setPublicKey(public_key[, encoding])
583 Sets the EC Diffie-Hellman public key. Key encoding can be `'binary'`,
584 `'hex'` or `'base64'`. If no encoding is provided, then a buffer is
587 ### ECDH.setPrivateKey(private_key[, encoding])
589 Sets the EC Diffie-Hellman private key. Key encoding can be `'binary'`,
590 `'hex'` or `'base64'`. If no encoding is provided, then a buffer is
593 Example (obtaining a shared secret):
595 var crypto = require('crypto');
596 var alice = crypto.createECDH('secp256k1');
597 var bob = crypto.createECDH('secp256k1');
599 alice.generateKeys();
602 var alice_secret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
603 var bob_secret = bob.computeSecret(alice.getPublicKey(), null, 'hex');
605 /* alice_secret and bob_secret should be the same */
606 console.log(alice_secret == bob_secret);
608 ## crypto.pbkdf2(password, salt, iterations, keylen[, digest], callback)
610 Asynchronous PBKDF2 function. Applies the selected HMAC digest function
611 (default: SHA1) to derive a key of the requested length from the password,
612 salt and number of iterations. The callback gets two arguments:
617 crypto.pbkdf2('secret', 'salt', 4096, 512, 'sha256', function(err, key) {
620 console.log(key.toString('hex')); // 'c5e478d...1469e50'
623 You can get a list of supported digest functions with
624 [crypto.getHashes()](#crypto_crypto_gethashes).
626 ## crypto.pbkdf2Sync(password, salt, iterations, keylen[, digest])
628 Synchronous PBKDF2 function. Returns derivedKey or throws error.
630 ## crypto.randomBytes(size[, callback])
632 Generates cryptographically strong pseudo-random data. Usage:
635 crypto.randomBytes(256, function(ex, buf) {
637 console.log('Have %d bytes of random data: %s', buf.length, buf);
642 var buf = crypto.randomBytes(256);
643 console.log('Have %d bytes of random data: %s', buf.length, buf);
646 // most likely, entropy sources are drained
649 NOTE: This will block if there is insufficient entropy, although it should
650 normally never take longer than a few milliseconds. The only time when this
651 may conceivably block is right after boot, when the whole system is still
654 ## Class: Certificate
656 The class used for working with signed public key & challenges. The most
657 common usage for this series of functions is when dealing with the `<keygen>`
658 element. http://www.openssl.org/docs/apps/spkac.html
660 Returned by `crypto.Certificate`.
662 ### Certificate.verifySpkac(spkac)
664 Returns true of false based on the validity of the SPKAC.
666 ### Certificate.exportChallenge(spkac)
668 Exports the encoded public key from the supplied SPKAC.
670 ### Certificate.exportPublicKey(spkac)
672 Exports the encoded challenge associated with the SPKAC.
674 ## crypto.publicEncrypt(public_key, buffer)
676 Encrypts `buffer` with `public_key`. Only RSA is currently supported.
678 `public_key` can be an object or a string. If `public_key` is a string, it is
679 treated as the key with no passphrase and will use `RSA_PKCS1_OAEP_PADDING`.
680 Since RSA public keys may be derived from private keys you may pass a private
685 * `key` : A string holding the PEM encoded private key
686 * `passphrase` : An optional string of passphrase for the private key
687 * `padding` : An optional padding value, one of the following:
688 * `constants.RSA_NO_PADDING`
689 * `constants.RSA_PKCS1_PADDING`
690 * `constants.RSA_PKCS1_OAEP_PADDING`
692 NOTE: All paddings are defined in `constants` module.
694 ## crypto.publicDecrypt(public_key, buffer)
696 See above for details. Has the same API as `crypto.publicEncrypt`. Default
697 padding is `RSA_PKCS1_PADDING`.
699 ## crypto.privateDecrypt(private_key, buffer)
701 Decrypts `buffer` with `private_key`.
703 `private_key` can be an object or a string. If `private_key` is a string, it is
704 treated as the key with no passphrase and will use `RSA_PKCS1_OAEP_PADDING`.
708 * `key` : A string holding the PEM encoded private key
709 * `passphrase` : An optional string of passphrase for the private key
710 * `padding` : An optional padding value, one of the following:
711 * `constants.RSA_NO_PADDING`
712 * `constants.RSA_PKCS1_PADDING`
713 * `constants.RSA_PKCS1_OAEP_PADDING`
715 NOTE: All paddings are defined in `constants` module.
717 ## crypto.privateEncrypt(private_key, buffer)
719 See above for details. Has the same API as `crypto.privateDecrypt`.
720 Default padding is `RSA_PKCS1_PADDING`.
722 ## crypto.DEFAULT_ENCODING
724 The default encoding to use for functions that can take either strings
725 or buffers. The default value is `'buffer'`, which makes it default
726 to using Buffer objects. This is here to make the crypto module more
727 easily compatible with legacy programs that expected `'binary'` to be
728 the default encoding.
730 Note that new programs will probably expect buffers, so only use this
731 as a temporary measure.
733 ## Recent API Changes
735 The Crypto module was added to Node.js before there was the concept of a
736 unified Stream API, and before there were Buffer objects for handling
739 As such, the streaming classes don't have the typical methods found on
740 other io.js classes, and many methods accepted and returned
741 Binary-encoded strings by default rather than Buffers. This was
742 changed to use Buffers by default instead.
744 This is a breaking change for some use cases, but not all.
746 For example, if you currently use the default arguments to the Sign
747 class, and then pass the results to the Verify class, without ever
748 inspecting the data, then it will continue to work as before. Where
749 you once got a binary string and then presented the binary string to
750 the Verify object, you'll now get a Buffer, and present the Buffer to
753 However, if you were doing things with the string data that will not
754 work properly on Buffers (such as, concatenating them, storing in
755 databases, etc.), or you are passing binary strings to the crypto
756 functions without an encoding argument, then you will need to start
757 providing encoding arguments to specify which encoding you'd like to
758 use. To switch to the previous style of using binary strings by
759 default, set the `crypto.DEFAULT_ENCODING` field to 'binary'. Note
760 that new programs will probably expect buffers, so only use this as a
764 [createCipher()]: #crypto_crypto_createcipher_algorithm_password
765 [createCipheriv()]: #crypto_crypto_createcipheriv_algorithm_key_iv
766 [crypto.createDiffieHellman()]: #crypto_crypto_creatediffiehellman_prime_prime_encoding_generator_generator_encoding
767 [tls.createSecureContext]: tls.html#tls_tls_createsecurecontext_details
768 [diffieHellman.setPublicKey()]: #crypto_diffiehellman_setpublickey_public_key_encoding
769 [RFC 2412]: http://www.rfc-editor.org/rfc/rfc2412.txt
770 [RFC 3526]: http://www.rfc-editor.org/rfc/rfc3526.txt
771 [crypto.pbkdf2]: #crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
772 [EVP_BytesToKey]: https://www.openssl.org/docs/crypto/EVP_BytesToKey.html