@@ -6,6 +6,10 @@ if (!common.hasCrypto) {
66 console . log ( '1..0 # Skipped: missing crypto' ) ;
77 return ;
88}
9+ if ( common . hasFipsCrypto ) {
10+ console . log ( '1..0 # Skipped: not supported in FIPS mode' ) ;
11+ return ;
12+ }
913var crypto = require ( 'crypto' ) ;
1014
1115function testCipher1 ( key ) {
@@ -62,71 +66,12 @@ function testCipher2(key) {
6266 assert . equal ( txt , plaintext , 'encryption and decryption with Base64' ) ;
6367}
6468
65-
66- function testCipher3 ( key , iv ) {
67- // Test encyrption and decryption with explicit key and iv
68- var plaintext =
69- '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
70- 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
71- 'jAfaFg**' ;
72- var cipher = crypto . createCipheriv ( 'des-ede3-cbc' , key , iv ) ;
73- var ciph = cipher . update ( plaintext , 'utf8' , 'hex' ) ;
74- ciph += cipher . final ( 'hex' ) ;
75-
76- var decipher = crypto . createDecipheriv ( 'des-ede3-cbc' , key , iv ) ;
77- var txt = decipher . update ( ciph , 'hex' , 'utf8' ) ;
78- txt += decipher . final ( 'utf8' ) ;
79-
80- assert . equal ( txt , plaintext , 'encryption and decryption with key and iv' ) ;
81-
82- // streaming cipher interface
83- // NB: In real life, it's not guaranteed that you can get all of it
84- // in a single read() like this. But in this case, we know it's
85- // quite small, so there's no harm.
86- var cStream = crypto . createCipheriv ( 'des-ede3-cbc' , key , iv ) ;
87- cStream . end ( plaintext ) ;
88- ciph = cStream . read ( ) ;
89-
90- var dStream = crypto . createDecipheriv ( 'des-ede3-cbc' , key , iv ) ;
91- dStream . end ( ciph ) ;
92- txt = dStream . read ( ) . toString ( 'utf8' ) ;
93-
94- assert . equal ( txt , plaintext , 'streaming cipher iv' ) ;
95- }
96-
97-
98- function testCipher4 ( key , iv ) {
99- // Test encyrption and decryption with explicit key and iv
100- var plaintext =
101- '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' +
102- 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' +
103- 'jAfaFg**' ;
104- var cipher = crypto . createCipheriv ( 'des-ede3-cbc' , key , iv ) ;
105- var ciph = cipher . update ( plaintext , 'utf8' , 'buffer' ) ;
106- ciph = Buffer . concat ( [ ciph , cipher . final ( 'buffer' ) ] ) ;
107-
108- var decipher = crypto . createDecipheriv ( 'des-ede3-cbc' , key , iv ) ;
109- var txt = decipher . update ( ciph , 'buffer' , 'utf8' ) ;
110- txt += decipher . final ( 'utf8' ) ;
111-
112- assert . equal ( txt , plaintext , 'encryption and decryption with key and iv' ) ;
113- }
114-
115-
11669testCipher1 ( 'MySecretKey123' ) ;
11770testCipher1 ( new Buffer ( 'MySecretKey123' ) ) ;
11871
11972testCipher2 ( '0123456789abcdef' ) ;
12073testCipher2 ( new Buffer ( '0123456789abcdef' ) ) ;
12174
122- testCipher3 ( '0123456789abcd0123456789' , '12345678' ) ;
123- testCipher3 ( '0123456789abcd0123456789' , new Buffer ( '12345678' ) ) ;
124- testCipher3 ( new Buffer ( '0123456789abcd0123456789' ) , '12345678' ) ;
125- testCipher3 ( new Buffer ( '0123456789abcd0123456789' ) , new Buffer ( '12345678' ) ) ;
126-
127- testCipher4 ( new Buffer ( '0123456789abcd0123456789' ) , new Buffer ( '12345678' ) ) ;
128-
129-
13075// Base64 padding regression test, see #4837.
13176( function ( ) {
13277 var c = crypto . createCipher ( 'aes-256-cbc' , 'secret' ) ;
0 commit comments