Back to all Bounties
Earn 2,250 ($22.50)
due 2 years ago
In Progress
Convert Java method to Javascript
martin-nginio
Details
Applications
4
Discussion
Bounty Description
Problem Description
Convert the following two Java methods into Javascript.
private static String signMessage(String secret, String data) {byte[] key = Base64.getUrlDecoder().decode(secret);byte[] signature = signMessage(key, "HmacSHA256", data);return Base64.getEncoder().encodeToString(signature);}private static byte[] signMessage(byte[] key, String algorithm, String data) {try {byte[] signature;Mac mac = Mac.getInstance(algorithm);SecretKeySpec keSpec = new SecretKeySpec(key, algorithm);mac.init(keSpec);signature = mac.doFinal(data.getBytes());return signature;} catch (NoSuchAlgorithmException | InvalidKeyException e) {throw new RuntimeException("Unable to signe the message: " + e.getMessage());}}
Acceptance Criteria
Both implementations have to produce identical results for different inputs. Secret input variable is usually base64 encoded.
The Javascript code should run on most modern brewers.
Using the following crypto lib in Javascript is preferred:
const crypto = require('crypto-js');