Skip to content

Commit

Permalink
fix: update secureBuffer cipherName
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan committed Jun 25, 2019
1 parent e21a428 commit b55fcde
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/secureBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
21 changes: 21 additions & 0 deletions test/unit/secureStringTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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();
}
});
});

0 comments on commit b55fcde

Please sign in to comment.