| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,25 +1,25 @@ | |||
| 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 | function testCipher1(key, iv) { | |
| 12 | 12 | // 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'); | ||
| 19 | 19 | ciph += cipher.final('hex'); | |
| 20 | 20 | ||
| 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'); | ||
| 23 | 23 | txt += decipher.final('utf8'); | |
| 24 | 24 | ||
| 25 | 25 | assert.strictEqual(txt, plaintext, 'encryption/decryption with key and iv'); | |
@@ -28,11 +28,11 @@ function testCipher1(key, iv) { | |||
| 28 | 28 | // NB: In real life, it's not guaranteed that you can get all of it | |
| 29 | 29 | // in a single read() like this. But in this case, we know it's | |
| 30 | 30 | // 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); | ||
| 32 | 32 | cStream.end(plaintext); | |
| 33 | 33 | ciph = cStream.read(); | |
| 34 | 34 | ||
| 35 | - var dStream = crypto.createDecipheriv('des-ede3-cbc', key, iv); | ||
| 35 | + const dStream = crypto.createDecipheriv('des-ede3-cbc', key, iv); | ||
| 36 | 36 | dStream.end(ciph); | |
| 37 | 37 | txt = dStream.read().toString('utf8'); | |
| 38 | 38 | ||
@@ -42,16 +42,16 @@ function testCipher1(key, iv) { | |||
| 42 | 42 | ||
| 43 | 43 | function testCipher2(key, iv) { | |
| 44 | 44 | // 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'); | ||
| 51 | 51 | ciph = Buffer.concat([ciph, cipher.final('buffer')]); | |
| 52 | 52 | ||
| 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'); | ||
| 55 | 55 | txt += decipher.final('utf8'); | |
| 56 | 56 | ||
| 57 | 57 | assert.strictEqual(txt, plaintext, 'encryption/decryption with key and iv'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments