11'use strict' ;
2- var common = require ( '../common' ) ;
3- var assert = require ( 'assert' ) ;
2+ const common = require ( '../common' ) ;
43
54if ( ! common . hasCrypto ) {
65 common . skip ( 'missing crypto' ) ;
@@ -10,21 +9,22 @@ if (common.hasFipsCrypto) {
109 common . skip ( 'not supported in FIPS mode' ) ;
1110 return ;
1211}
13- var crypto = require ( 'crypto' ) ;
12+ const crypto = require ( 'crypto' ) ;
13+ const assert = require ( 'assert' ) ;
1414
1515function testCipher1 ( key ) {
1616 // Test encryption and decryption
17- var plaintext = 'Keep this a secret? No! Tell everyone about node.js!' ;
18- var cipher = crypto . createCipher ( 'aes192' , key ) ;
17+ const plaintext = 'Keep this a secret? No! Tell everyone about node.js!' ;
18+ const cipher = crypto . createCipher ( 'aes192' , key ) ;
1919
2020 // encrypt plaintext which is in utf8 format
2121 // to a ciphertext which will be in hex
22- var ciph = cipher . update ( plaintext , 'utf8' , 'hex' ) ;
22+ let ciph = cipher . update ( plaintext , 'utf8' , 'hex' ) ;
2323 // Only use binary or hex, not base64.
2424 ciph += cipher . final ( 'hex' ) ;
2525
26- var decipher = crypto . createDecipher ( 'aes192' , key ) ;
27- var txt = decipher . update ( ciph , 'hex' , 'utf8' ) ;
26+ const decipher = crypto . createDecipher ( 'aes192' , key ) ;
27+ let txt = decipher . update ( ciph , 'hex' , 'utf8' ) ;
2828 txt += decipher . final ( 'utf8' ) ;
2929
3030 assert . strictEqual ( txt , plaintext , 'encryption and decryption' ) ;
@@ -33,11 +33,11 @@ function testCipher1(key) {
3333 // NB: In real life, it's not guaranteed that you can get all of it
3434 // in a single read() like this. But in this case, we know it's
3535 // quite small, so there's no harm.
36- var cStream = crypto . createCipher ( 'aes192' , key ) ;
36+ const cStream = crypto . createCipher ( 'aes192' , key ) ;
3737 cStream . end ( plaintext ) ;
3838 ciph = cStream . read ( ) ;
3939
40- var dStream = crypto . createDecipher ( 'aes192' , key ) ;
40+ const dStream = crypto . createDecipher ( 'aes192' , key ) ;
4141 dStream . end ( ciph ) ;
4242 txt = dStream . read ( ) . toString ( 'utf8' ) ;
4343
@@ -48,19 +48,19 @@ function testCipher1(key) {
4848function testCipher2 ( key ) {
4949 // encryption and decryption with Base64
5050 // reported in https://github.com/joyent/node/issues/738
51- var plaintext =
51+ const plaintext =
5252 '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
5353 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
5454 'jAfaFg**' ;
55- var cipher = crypto . createCipher ( 'aes256' , key ) ;
55+ const cipher = crypto . createCipher ( 'aes256' , key ) ;
5656
5757 // encrypt plaintext which is in utf8 format
5858 // to a ciphertext which will be in Base64
59- var ciph = cipher . update ( plaintext , 'utf8' , 'base64' ) ;
59+ let ciph = cipher . update ( plaintext , 'utf8' , 'base64' ) ;
6060 ciph += cipher . final ( 'base64' ) ;
6161
62- var decipher = crypto . createDecipher ( 'aes256' , key ) ;
63- var txt = decipher . update ( ciph , 'base64' , 'utf8' ) ;
62+ const decipher = crypto . createDecipher ( 'aes256' , key ) ;
63+ let txt = decipher . update ( ciph , 'base64' , 'utf8' ) ;
6464 txt += decipher . final ( 'utf8' ) ;
6565
6666 assert . strictEqual ( txt , plaintext , 'encryption and decryption with Base64' ) ;
@@ -119,12 +119,12 @@ testCipher2(Buffer.from('0123456789abcdef'));
119119 const key = '0123456789abcdef' ;
120120 const plaintext = 'Top secret!!!' ;
121121 const c = crypto . createCipher ( 'aes192' , key ) ;
122- var ciph = c . update ( plaintext , 'utf16le' , 'base64' ) ;
122+ let ciph = c . update ( plaintext , 'utf16le' , 'base64' ) ;
123123 ciph += c . final ( 'base64' ) ;
124124
125- var decipher = crypto . createDecipher ( 'aes192' , key ) ;
125+ let decipher = crypto . createDecipher ( 'aes192' , key ) ;
126126
127- var txt ;
127+ let txt ;
128128 assert . doesNotThrow ( ( ) => txt = decipher . update ( ciph , 'base64' , 'ucs2' ) ) ;
129129 assert . doesNotThrow ( ( ) => txt += decipher . final ( 'ucs2' ) ) ;
130130 assert . strictEqual ( txt , plaintext , 'decrypted result in ucs2' ) ;
0 commit comments