What version of Bun is running?

0.5.1

What platform is your computer?

Darwin 22.3.0 arm64 arm

What steps can reproduce the bug?

Currently trying to use the Node Crypto APIs to be able to generate a signed string which causes an error:

import { createHmac } from "crypto";

export async function signString(key: string, toSign: string): Promise<string> {
  const hmac = createHmac("sha256", key).update(toSign).digest("base64");
  return encodeURIComponent(hmac);
}

What is the expected behavior?

The following code should just work:

import { createHmac } from "crypto";

const result = crypto.createHmac('sha256', "key").update("message").digest("base64");
'bp7ym3X//Ft6uuUn1Y/a2y/kLnIZARl2kXNDBl9Y7Uo='

What do you see instead?

Running a sample through this gives me the following error:

1206 |         (this._encoding = null);
1207 |     }
1208 |     inherits(CipherBase, Transform);
1209 |     CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
1210 |
1211 |       typeof data == "string" && (data = Buffer2.from(data, inputEnc));
                                            ^
TypeError: Invalid encoding
      at node:crypto:1211:41

Additional information

No response

0

Thank you for the minimum repro

0
© 2022 pullanswer.com - All rights reserved.