I've this encryption method in Scala, which I want to convert to NodeJS for a microservice:
val key = "very-secret-key"
val id1 = "1001"
val id2 = "2002"
val id3 = "3003"
val mac = Mac.getInstance("hmacSHA256")
mac.init(new SecretKeySpec(key.getBytes, "hmacSHA256"))
val digest = mac.doFinal(id1.getBytes ++ id2.getBytes ++ id3.getBytes)
new String(UrlBase64.encode(digest)).replace(".", "")
tried to do this with createHmac from crypto and converting to Bytes with Buffer but the output token is not the same as in the one I generate in Java
import { createHmac } from 'crypto';
const id1 = Buffer.from('1001', 'base64');
const id2 = Buffer.from('2002', 'base64');
const id3 = Buffer.from('3003', 'base64');
const buffer = Buffer.from("very-secret-key", 'base64');
const token = createHmac('sha256', buffer).digest('base64').replace('.', '');
I'm stuck trying to figure how to add the buffer bytes to the token mac.doFinal(id1.getBytes ++ id2.getBytes ++ id3.getBytes)