11'use strict' ;
2- var common = require ( '../common' ) ;
3- var assert = require ( 'assert' ) ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
44
55if ( ! common . hasCrypto ) {
66common . skip ( 'missing crypto' ) ;
77return ;
88}
9- var crypto = require ( 'crypto' ) ;
9+ const crypto = require ( 'crypto' ) ;
1010
1111function testCipher1 ( key , iv ) {
1212// Test encyrption and decryption with explicit key and iv
13- var plaintext =
14- '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
15- 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
16- 'jAfaFg**' ;
17- var cipher = crypto . createCipheriv ( 'des-ede3-cbc' , key , iv ) ;
18- var ciph = cipher . update ( plaintext , 'utf8' , 'hex' ) ;
13+ const plaintext =
14+ '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
15+ 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
16+ 'jAfaFg**' ;
17+ const cipher = crypto . createCipheriv ( 'des-ede3-cbc' , key , iv ) ;
18+ let ciph = cipher . update ( plaintext , 'utf8' , 'hex' ) ;
1919ciph += cipher . final ( 'hex' ) ;
2020
21- var decipher = crypto . createDecipheriv ( 'des-ede3-cbc' , key , iv ) ;
22- var txt = decipher . update ( ciph , 'hex' , 'utf8' ) ;
21+ const decipher = crypto . createDecipheriv ( 'des-ede3-cbc' , key , iv ) ;
22+ let txt = decipher . update ( ciph , 'hex' , 'utf8' ) ;
2323txt += decipher . final ( 'utf8' ) ;
2424
2525assert . strictEqual ( txt , plaintext , 'encryption/decryption with key and iv' ) ;
@@ -28,11 +28,11 @@ function testCipher1(key, iv){
2828// NB: In real life, it's not guaranteed that you can get all of it
2929// in a single read() like this. But in this case, we know it's
3030// quite small, so there's no harm.
31- var cStream = crypto . createCipheriv ( 'des-ede3-cbc' , key , iv ) ;
31+ const cStream = crypto . createCipheriv ( 'des-ede3-cbc' , key , iv ) ;
3232cStream . end ( plaintext ) ;
3333ciph = cStream . read ( ) ;
3434
35- var dStream = crypto . createDecipheriv ( 'des-ede3-cbc' , key , iv ) ;
35+ const dStream = crypto . createDecipheriv ( 'des-ede3-cbc' , key , iv ) ;
3636dStream . end ( ciph ) ;
3737txt = dStream . read ( ) . toString ( 'utf8' ) ;
3838
@@ -42,16 +42,16 @@ function testCipher1(key, iv){
4242
4343function testCipher2 ( key , iv ) {
4444// Test encyrption and decryption with explicit key and iv
45- var plaintext =
46- '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
47- 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
48- 'jAfaFg**' ;
49- var cipher = crypto . createCipheriv ( 'des-ede3-cbc' , key , iv ) ;
50- var ciph = cipher . update ( plaintext , 'utf8' , 'buffer' ) ;
45+ const plaintext =
46+ '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
47+ 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
48+ 'jAfaFg**' ;
49+ const cipher = crypto . createCipheriv ( 'des-ede3-cbc' , key , iv ) ;
50+ let ciph = cipher . update ( plaintext , 'utf8' , 'buffer' ) ;
5151ciph = Buffer . concat ( [ ciph , cipher . final ( 'buffer' ) ] ) ;
5252
53- var decipher = crypto . createDecipheriv ( 'des-ede3-cbc' , key , iv ) ;
54- var txt = decipher . update ( ciph , 'buffer' , 'utf8' ) ;
53+ const decipher = crypto . createDecipheriv ( 'des-ede3-cbc' , key , iv ) ;
54+ let txt = decipher . update ( ciph , 'buffer' , 'utf8' ) ;
5555txt += decipher . final ( 'utf8' ) ;
5656
5757assert . strictEqual ( txt , plaintext , 'encryption/decryption with key and iv' ) ;
0 commit comments