1
1
'use strict' ;
2
- var common = require ( '../common' ) ;
3
- var assert = require ( 'assert' ) ;
2
+ const common = require ( '../common' ) ;
3
+ const assert = require ( 'assert' ) ;
4
4
5
5
if ( ! common . hasCrypto ) {
6
6
common . skip ( 'missing crypto' ) ;
7
7
return ;
8
8
}
9
- var crypto = require ( 'crypto' ) ;
9
+ const crypto = require ( 'crypto' ) ;
10
10
11
11
crypto . DEFAULT_ENCODING = 'buffer' ;
12
12
@@ -21,7 +21,7 @@ const EVEN_LENGTH_PLAIN = 'Hello node world!AbC09876dDeFgHi';
21
21
const KEY_PLAIN = 'S3c.r.e.t.K.e.Y!' ;
22
22
const IV_PLAIN = 'blahFizz2011Buzz' ;
23
23
24
- var CIPHER_NAME = 'aes-128-cbc' ;
24
+ const CIPHER_NAME = 'aes-128-cbc' ;
25
25
26
26
27
27
/*
@@ -31,20 +31,20 @@ var CIPHER_NAME = 'aes-128-cbc';
31
31
// echo -n 'Hello node world!' | \
32
32
// openssl enc -aes-128-cbc -e -K 5333632e722e652e742e4b2e652e5921 \
33
33
// -iv 626c616846697a7a3230313142757a7a | xxd -p -c256
34
- var ODD_LENGTH_ENCRYPTED =
34
+ const ODD_LENGTH_ENCRYPTED =
35
35
'7f57859550d4d2fdb9806da2a750461a9fe77253cd1cbd4b07beee4e070d561f' ;
36
36
37
37
// echo -n 'Hello node world!AbC09876dDeFgHi' | \
38
38
// openssl enc -aes-128-cbc -e -K 5333632e722e652e742e4b2e652e5921 \
39
39
// -iv 626c616846697a7a3230313142757a7a | xxd -p -c256
40
- var EVEN_LENGTH_ENCRYPTED =
40
+ const EVEN_LENGTH_ENCRYPTED =
41
41
'7f57859550d4d2fdb9806da2a750461ab46e71b3d78ebe2d9684dfc87f7575b988' +
42
42
'6119866912cb8c7bcaf76c5ebc2378' ;
43
43
44
44
// echo -n 'Hello node world!AbC09876dDeFgHi' | \
45
45
// openssl enc -aes-128-cbc -e -K 5333632e722e652e742e4b2e652e5921 \
46
46
// -iv 626c616846697a7a3230313142757a7a -nopad | xxd -p -c256
47
- var EVEN_LENGTH_ENCRYPTED_NOPAD =
47
+ const EVEN_LENGTH_ENCRYPTED_NOPAD =
48
48
'7f57859550d4d2fdb9806da2a750461ab46e' +
49
49
'71b3d78ebe2d9684dfc87f7575b9' ;
50
50
@@ -54,17 +54,17 @@ var EVEN_LENGTH_ENCRYPTED_NOPAD =
54
54
*/
55
55
56
56
function enc ( plain , pad ) {
57
- var encrypt = crypto . createCipheriv ( CIPHER_NAME , KEY_PLAIN , IV_PLAIN ) ;
57
+ const encrypt = crypto . createCipheriv ( CIPHER_NAME , KEY_PLAIN , IV_PLAIN ) ;
58
58
encrypt . setAutoPadding ( pad ) ;
59
- var hex = encrypt . update ( plain , 'ascii' , 'hex' ) ;
59
+ let hex = encrypt . update ( plain , 'ascii' , 'hex' ) ;
60
60
hex += encrypt . final ( 'hex' ) ;
61
61
return hex ;
62
62
}
63
63
64
64
function dec ( encd , pad ) {
65
- var decrypt = crypto . createDecipheriv ( CIPHER_NAME , KEY_PLAIN , IV_PLAIN ) ;
65
+ const decrypt = crypto . createDecipheriv ( CIPHER_NAME , KEY_PLAIN , IV_PLAIN ) ;
66
66
decrypt . setAutoPadding ( pad ) ;
67
- var plain = decrypt . update ( encd , 'hex' ) ;
67
+ let plain = decrypt . update ( encd , 'hex' ) ;
68
68
plain += decrypt . final ( 'latin1' ) ;
69
69
return plain ;
70
70
}
@@ -104,9 +104,7 @@ assert.doesNotThrow(function() {
104
104
105
105
assert . throws ( function ( ) {
106
106
// must have at least 1 byte of padding (PKCS):
107
- assert . strictEqual (
108
- dec ( EVEN_LENGTH_ENCRYPTED_NOPAD , true ) , EVEN_LENGTH_PLAIN
109
- ) ;
107
+ assert . strictEqual ( dec ( EVEN_LENGTH_ENCRYPTED_NOPAD , true ) , EVEN_LENGTH_PLAIN ) ;
110
108
} , / b a d d e c r y p t / ) ;
111
109
112
110
assert . doesNotThrow ( function ( ) {
0 commit comments