You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/ethereum-cryptography/README.md
+35-13Lines changed: 35 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -267,16 +267,15 @@ like [pbkdf2](#pbkdf2-submodule) or [scrypt](#scrypt-submodule).
267
267
268
268
### Operation modes
269
269
270
-
This submodule works with different [block cipher modes of operation](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation).
271
-
To choose one of them, you should pass the `mode` parameter a string with the
272
-
same format as OpenSSL and Node use. You can take a look at them by running
273
-
`openssl list -cipher-algorithms`.
270
+
This submodule works with different [block cipher modes of operation](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation). If you are using this module in a new
271
+
application, we recommend using the default.
274
272
275
-
In Node, any mode that its OpenSSL version supports can be used.
273
+
While this module may work with any mode supported by OpenSSL, we only test it
274
+
with `aes-128-ctr`, `aes-128-cbc`, and `aes-256-cbc`. If you use another module
275
+
a warning will be printed in the console.
276
276
277
-
In the browser, we test it to work with the modes that are normally used in
278
-
Ethereum libraries and applications. Those are `aes-128-ctr`, `aes-126-cbc`, and
279
-
`aes-256-cbc`, but other modes may work.
277
+
We only recommend using `aes-128-cbc` and `aes-256-cbc` to decrypt already
278
+
encrypted data.
280
279
281
280
### Padding plaintext messages
282
281
@@ -292,14 +291,38 @@ If you need to encrypt without padding or want to use another padding scheme,
292
291
you can disable PKCS#7 padding by passing `false` as the last argument and
293
292
handling padding yourself. Note that if you do this and your operation mode
294
293
requires padding, `encrypt` will throw if your plaintext message isn't a
295
-
multiple of `16.
294
+
multiple of `16`.
295
+
296
+
This option is only present to enable the decryption of already encrypted data.
297
+
To encrypt new data, we recommend using the default.
298
+
299
+
### IV reusing
300
+
301
+
The `iv` parameter of the `encrypt` function must be unique, or the security
302
+
of the encryption algorithm can be compromissed.
303
+
304
+
You can generate a new `iv` using the `random` module.
305
+
306
+
Note that to decrypt a value, you have to provide the same `iv` used to encrypt
307
+
it.
308
+
309
+
### How to handle errors with this module
310
+
311
+
Sensitive information can be leaked via error messages when using this module.
312
+
To avoid this, you should make sure that the errors you return don't
313
+
contain the exact reason for the error. Instead, errors must report general
314
+
encryption/decryption failures.
315
+
316
+
Note that implementing this can mean catching all errors that can be thrown
317
+
when calling on of this module's functions, and just throwing a new generic
318
+
exception.
296
319
297
320
### Function types
298
321
299
322
```ts
300
-
function encrypt(msg:Buffer, key:Buffer, iv:Buffer, mode:string, pkcs7PaddingEnabled=true):Buffer;
323
+
function encrypt(msg:Buffer, key:Buffer, iv:Buffer, mode="aes-128-ctr", pkcs7PaddingEnabled=true):Buffer;
301
324
302
-
function decrypt(cypherText:Buffer, key:Buffer, iv:Buffer, mode:string, pkcs7PaddingEnabled=true):Buffer
325
+
function decrypt(cypherText:Buffer, key:Buffer, iv:Buffer, mode="aes-128-ctr", pkcs7PaddingEnabled=true):Buffer
0 commit comments