-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto: Deprecate createCipher for createCipheriv #13941
Changes from 11 commits
cc8976b
3d0b5a5
1e810d0
8f2b81f
7f913ec
b7abe64
b16018a
39a2112
d0f2778
14e0566
3f0fdb2
b0fe314
0025983
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1171,7 +1171,11 @@ currently in use. Setting to true requires a FIPS build of Node.js. | |
### crypto.createCipher(algorithm, password) | ||
<!-- YAML | ||
added: v0.1.94 | ||
deprecated: vx.x.x | ||
--> | ||
|
||
> Stability: 0 - Deprecated: Use [`crypto.createCipheriv()`][] instead. | ||
|
||
- `algorithm` {string} | ||
- `password` {string | Buffer | TypedArray | DataView} | ||
|
||
|
@@ -1214,6 +1218,44 @@ The `key` is the raw key used by the `algorithm` and `iv` is an | |
[initialization vector][]. Both arguments must be `'utf8'` encoded strings, | ||
[Buffers][`Buffer`], `TypedArray`, or `DataView`s. | ||
|
||
### crypto.generateLegacyKey(algorithm, key) | ||
- `algorithm` {string} | ||
- `key` {string | Buffer | TypedArray | DataView} | ||
|
||
Creates and returns a [Buffer][`Buffer`] object, with the given `algorithm` and | ||
`key`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your docs seem to miss information about what the functions actually do. |
||
|
||
Use this function for applications previously reliant on | ||
[`crypto.createCipher()`][]. Pass its return value to | ||
[`crypto.createCipheriv()`][] as the `key`. | ||
|
||
The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On | ||
recent OpenSSL releases, `openssl list-cipher-algorithms` will display the | ||
available cipher algorithms. | ||
|
||
The `key` must be a `'utf8'` encoded string, [Buffer][`Buffer`], `TypedArray`, | ||
or `DataView`. | ||
|
||
### crypto.generateLegacyIV(algorithm, iv) | ||
- `algorithm` {string} | ||
- `iv` {string | Buffer | TypedArray | DataView} | ||
|
||
Creates and returns a [Buffer][`Buffer`] object, with the given `algorithm` and | ||
`iv`. | ||
|
||
Use this function for applications previously reliant on | ||
[`crypto.createCipher()`][]. Pass its return value to | ||
[`crypto.createCipheriv()`][] as the `iv`. | ||
|
||
The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On | ||
recent OpenSSL releases, `openssl list-cipher-algorithms` will display the | ||
available cipher algorithms. | ||
|
||
This function will throw an error if a cipher without an IV is passed. | ||
|
||
The `iv` must be a `'utf8'` encoded string, [Buffer][`Buffer`], `TypedArray`, | ||
or `DataView`. | ||
|
||
### crypto.createCredentials(details) | ||
<!-- YAML | ||
added: v0.1.92 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -634,6 +634,36 @@ Type: Runtime | |
|
||
*Note*: change was made while `async_hooks` was an experimental API. | ||
|
||
<a id="DEP00XX"></a> | ||
### DEP00XX: crypto.createCipher() | ||
|
||
Type: Runtime | ||
|
||
[`crypto.createCipher()`][] generates keys from strings in an insecure manner, | ||
and, when used with a cipher that utilizes an initialization vector, will | ||
dangerously re-use initialization vectors. As such, it is immediately marked as | ||
deprecated, and will be fully removed in a later version. | ||
|
||
[`crypto.createCipheriv()`][] should be used in place of | ||
[`crypto.createCipher()`][]. Since [`crypto.createCipheriv()`][] will no longer | ||
attempt to derive a proper encryption key from a string, you must use a | ||
key-derivation function such as [`crypto.pbkdf2()`][] to obtain a valid key if | ||
you normally supply a string to [`crypto.createCipher()`][]. | ||
|
||
If the previous key-derivation is required for backward compatiability, the new | ||
APIs [`crypto.generateLegacyKey()`][] and [`crypto.generateLegacyIV()`][] have | ||
been added. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really a causality. |
||
|
||
Additionally, for ciphers that require an initialization vector, a proper-length | ||
initialization vector must be passed to [`crypto.createCipheriv()`][]. | ||
Initialization vectors must never be re-used, especially in modes such as | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
AES-CTR, where encryption is effectively removed upon reuse. Applications will | ||
need to store this initialization vector along with the encrypted data, as it is | ||
required for decryption. | ||
|
||
If an initialization vector is not needed by the cipher, pass `null` or omit the | ||
argument. | ||
|
||
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size | ||
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array | ||
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer | ||
|
@@ -647,6 +677,10 @@ Type: Runtime | |
[`child_process`]: child_process.html | ||
[`console.error()`]: console.html#console_console_error_data_args | ||
[`console.log()`]: console.html#console_console_log_data_args | ||
[`crypto.createCipher()`]: crypto.html#crypto_crypto_createcipher_algorithm_password | ||
[`crypto.createCipheriv()`]: crypto.html#crypto_crypto_createcipheriv_algorithm_key_iv | ||
[`crypto.generateLegacyKey()`]: crypto.html#crypto_crypto_generatelegacykey_algorithm_key | ||
[`crypto.generateLegacyIV()`]: crypto.html#crypto_crypto_generatelegacyiv_algorithm_iv | ||
[`crypto.createCredentials()`]: crypto.html#crypto_crypto_createcredentials_details | ||
[`crypto.pbkdf2()`]: crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback | ||
[`domain`]: domain.html | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
const
instead ofvar
.