| 9 | const isFipsEnabled = crypto.getFips(); |
| 10 | |
| 11 | function testCipher1(key, iv) { |
| 12 | // Test encryption and decryption with explicit key and iv |
| 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'); |
| 19 | ciph += cipher.final('hex'); |
| 20 | |
| 21 | const decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv); |
| 22 | let txt = decipher.update(ciph, 'hex', 'utf8'); |
| 23 | txt += decipher.final('utf8'); |
| 24 | |
| 25 | assert.strictEqual(txt, plaintext, |
| 26 | `encryption/decryption with key ${key} and iv ${iv}`); |
| 27 | |
| 28 | // Streaming cipher interface |
| 29 | // NB: In real life, it's not guaranteed that you can get all of it |
| 30 | // in a single read() like this. But in this case, we know it's |
| 31 | // quite small, so there's no harm. |
| 32 | const cStream = crypto.createCipheriv('des-ede3-cbc', key, iv); |
| 33 | cStream.end(plaintext); |
| 34 | ciph = cStream.read(cStream.readableLength); |
| 35 | |
| 36 | const dStream = crypto.createDecipheriv('des-ede3-cbc', key, iv); |
| 37 | dStream.end(ciph); |
| 38 | txt = dStream.read(dStream.readableLength).toString('utf8'); |
| 39 | |
| 40 | assert.strictEqual(txt, plaintext, |
| 41 | `streaming cipher with key ${key} and iv ${iv}`); |
| 42 | } |
| 43 | |
| 44 | |
| 45 | function testCipher2(key, iv) { |