• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5
6const assert = require('assert');
7const crypto = require('crypto');
8
9const test = [
10  {
11    algorithm: 'aes128-wrap',
12    key: 'b26f309fbe57e9b3bb6ae5ef31d54450',
13    iv: '3fd838af4093d749',
14    text: '12345678123456781234567812345678'
15  },
16  {
17    algorithm: 'id-aes128-wrap-pad',
18    key: 'b26f309fbe57e9b3bb6ae5ef31d54450',
19    iv: '3fd838af',
20    text: '12345678123456781234567812345678123'
21  },
22  {
23    algorithm: 'aes192-wrap',
24    key: '40978085d68091f7dfca0d7dfc7a5ee76d2cc7f2f345a304',
25    iv: '3fd838af4093d749',
26    text: '12345678123456781234567812345678'
27  },
28  {
29    algorithm: 'id-aes192-wrap-pad',
30    key: '40978085d68091f7dfca0d7dfc7a5ee76d2cc7f2f345a304',
31    iv: '3fd838af',
32    text: '12345678123456781234567812345678123'
33  },
34  {
35    algorithm: 'aes256-wrap',
36    key: '29c9eab5ed5ad44134a1437fe2e673b4d88a5b7c72e68454fea08721392b7323',
37    iv: '3fd838af4093d749',
38    text: '12345678123456781234567812345678'
39  },
40  {
41    algorithm: 'id-aes256-wrap-pad',
42    key: '29c9eab5ed5ad44134a1437fe2e673b4d88a5b7c72e68454fea08721392b7323',
43    iv: '3fd838af',
44    text: '12345678123456781234567812345678123'
45  },
46];
47
48test.forEach((data) => {
49  const cipher = crypto.createCipheriv(
50    data.algorithm,
51    Buffer.from(data.key, 'hex'),
52    Buffer.from(data.iv, 'hex'));
53  const ciphertext = cipher.update(data.text, 'utf8');
54
55  const decipher = crypto.createDecipheriv(
56    data.algorithm,
57    Buffer.from(data.key, 'hex'),
58    Buffer.from(data.iv, 'hex'));
59  const msg = decipher.update(ciphertext, 'buffer', 'utf8');
60
61  assert.strictEqual(msg, data.text, `${data.algorithm} test case failed`);
62});
63