diff --git a/src/secureBuffer.ts b/src/secureBuffer.ts index bb60abeb98..495f43545d 100644 --- a/src/secureBuffer.ts +++ b/src/secureBuffer.ts @@ -8,7 +8,7 @@ import { ensure, Optional } from '@salesforce/ts-types'; import * as crypto from 'crypto'; -const cipherName = 'aes256'; +const cipherName = 'aes-256-cbc'; const cipherSize = 32; /** diff --git a/test/unit/secureStringTest.ts b/test/unit/secureStringTest.ts index 1c3cca0c06..4d636c691c 100644 --- a/test/unit/secureStringTest.ts +++ b/test/unit/secureStringTest.ts @@ -5,6 +5,8 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ import { expect } from 'chai'; +import * as crypto from 'crypto'; +import { stub } from 'sinon'; import { SecureBuffer } from '../../src/secureBuffer'; describe('secureBuffer', async () => { @@ -49,4 +51,23 @@ describe('secureBuffer', async () => { expect(buffer.toString('utf8')).to.not.be.equal(secretText); }); }); + + it('test backwards compatibility between aes256 and aes-256-cbc', () => { + const key = Buffer.from('aaaabbbbccccddddeeeeffffgggghhhh'); + const iv = Buffer.from('aaaabbbbccccdddd'); + const cipher = crypto.createCipheriv('aes256', key, iv); + const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv); + const createCipherStub = stub(crypto, 'createCipheriv').returns(cipher); + const createDecipherStub = stub(crypto, 'createDecipheriv').returns(decipher); + try { + const secure = new SecureBuffer(); + secure.consume(Buffer.from(secretText, 'utf8')); + expect(createCipherStub.calledOnce).to.be.true; + secure.value(val => expect(val.toString('utf8')).to.be.equal(secretText)); + expect(createDecipherStub.calledOnce).to.be.true; + } finally { + createCipherStub.restore(); + createDecipherStub.restore(); + } + }); });