Skip to content

Commit 8263e71

Browse files
authored
Use configured ivFieldName during encryption (#38)
1 parent c9cca0a commit 8263e71

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/mcapi/crypto/field-level-crypto.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ function FieldLevelCrypto(config) {
4141

4242
this.oaepHashingAlgorithmFieldName = config.oaepHashingAlgorithmFieldName;
4343

44+
this.ivFieldName = config.ivFieldName || 'iv';
45+
4446
/**
4547
* Perform data encryption
4648
*
@@ -71,7 +73,7 @@ function FieldLevelCrypto(config) {
7173
encrypted,
7274
this.encoding
7375
),
74-
iv: utils.bytesToString(enc.iv, this.encoding),
76+
[this.ivFieldName]: utils.bytesToString(enc.iv, this.encoding),
7577
[this.encryptedKeyFieldName]: utils.bytesToString(
7678
enc.encryptedKey,
7779
this.encoding

test/field-level-crypto.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,25 @@ describe("Field Level Crypto", () => {
222222
assert.ok(resp.iv);
223223
assert.ok(resp.oaepHashingAlgorithm);
224224
});
225+
226+
it("with custom ivFieldName object", () => {
227+
const config = JSON.parse(JSON.stringify(testConfig));
228+
config.ivFieldName = 'IvCustomName';
229+
const crypto = new Crypto(config);
230+
const data = JSON.stringify({ text: "message with custom ivFieldName" });
231+
const resp = crypto.encryptData({
232+
data: data,
233+
});
234+
assert.ok(resp);
235+
assert.ok(resp.encryptedKey);
236+
assert.ok(resp.encryptedData);
237+
assert.ok(resp.IvCustomName);
238+
assert.ok(!resp.iv);
239+
assert.ok(resp.oaepHashingAlgorithm);
240+
});
225241
});
226242

243+
227244
describe("#decryptData()", () => {
228245
let crypto;
229246
before(() => {

0 commit comments

Comments
 (0)