Skip to content

Commit 7e46c1f

Browse files
authored
fix algorithms fallback functions (#285)
1 parent 8126622 commit 7e46c1f

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

lib/algorithms/aes-cbc-hmac-sha2.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function commonCbcEncryptFN(size) {
4141
return Promise.reject(new Error("encryption failed"));
4242
}
4343

44-
var cdata = cipher.output.native();
44+
var cdata = Buffer.from(cipher.output.bytes(), "binary");
4545
return cdata;
4646
});
4747

@@ -130,7 +130,7 @@ function commonCbcDecryptFN(size) {
130130
return Promise.reject(new Error("encryption failed"));
131131
}
132132

133-
var pdata = cipher.output.native();
133+
var pdata = Buffer.from(cipher.output.bytes(), "binary");
134134
return pdata;
135135
});
136136

lib/algorithms/aes-kw.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function kwEncryptFN(size) {
7878
cipher.start();
7979
cipher.update(new DataBuffer(B));
8080
cipher.finish();
81-
B = cipher.output.native();
81+
B = Buffer.from(cipher.output.bytes(), "binary");
8282

8383
A = xor(B.slice(0, 8),
8484
longToBigEndian(count));
@@ -194,7 +194,7 @@ function kwDecryptFN(size) {
194194
cipher.start();
195195
cipher.update(new DataBuffer(B));
196196
cipher.finish();
197-
B = cipher.output.native();
197+
B = Buffer.from(cipher.output.bytes(), "binary");
198198

199199
A = B.slice(0, 8);
200200
R[idx] = B.slice(8, 16);

lib/algorithms/hmac.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ function hmacSignFN(name) {
3131
promise = promise.then(function() {
3232
var sig = forge.hmac.create();
3333
sig.start(md, key.toString("binary"));
34-
sig.update(pdata);
35-
sig = sig.digest().native();
34+
sig.update(pdata.toString("binary"));
35+
sig = Buffer.from(sig.digest().bytes(), "binary");
3636

3737
return {
3838
data: pdata,
@@ -112,8 +112,8 @@ function hmacVerifyFN(name) {
112112

113113
var vrfy = forge.hmac.create();
114114
vrfy.start(md, new DataBuffer(key));
115-
vrfy.update(pdata);
116-
vrfy = vrfy.digest().native();
115+
vrfy.update(pdata.toString("binary"));
116+
vrfy = Buffer.from(vrfy.digest().bytes(), "binary");
117117

118118
if (compare(props.length, mac, vrfy)) {
119119
return Promise.resolve({

lib/algorithms/sha.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function hashDigestFN(hash) {
1818
// ### Fallback Implementation -- uses forge
1919
var fallback = function(pdata /* props */) {
2020
var digest = forge.md[md].create();
21-
digest.update(pdata);
22-
digest = digest.digest().native();
21+
digest.update(pdata.toString("binary"));
22+
digest = Buffer.from(digest.digest().bytes(), "binary");
2323

2424
return Promise.resolve(digest);
2525
};

0 commit comments

Comments
 (0)