| 62 | |
| 63 | |
| 64 | function testCipher3(key, iv) { |
| 65 | if (!crypto.getCiphers().includes('id-aes128-wrap')) { |
| 66 | common.printSkipMessage(`unsupported id-aes128-wrap test`); |
| 67 | return; |
| 68 | } |
| 69 | // Test encryption and decryption with explicit key and iv. |
| 70 | // AES Key Wrap test vector comes from RFC3394 |
| 71 | const plaintext = Buffer.from('00112233445566778899AABBCCDDEEFF', 'hex'); |
| 72 | |
| 73 | const cipher = crypto.createCipheriv('id-aes128-wrap', key, iv); |
| 74 | let ciph = cipher.update(plaintext, 'utf8', 'buffer'); |
| 75 | ciph = Buffer.concat([ciph, cipher.final('buffer')]); |
| 76 | const ciph2 = Buffer.from('1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5', |
| 77 | 'hex'); |
| 78 | assert(ciph.equals(ciph2)); |
| 79 | const decipher = crypto.createDecipheriv('id-aes128-wrap', key, iv); |
| 80 | let deciph = decipher.update(ciph, 'buffer'); |
| 81 | deciph = Buffer.concat([deciph, decipher.final()]); |
| 82 | |
| 83 | assert(deciph.equals(plaintext), |
| 84 | `encryption/decryption with key ${key} and iv ${iv}`); |
| 85 | } |
| 86 | |
| 87 | { |
| 88 | const Cipheriv = crypto.Cipheriv; |