Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function verifyHmac (
payload: IEncryptionPayload,
key: ArrayBuffer
): Promise {
const cipherText: ArrayBuffer = convertHexToArrayBuffer(payload.data)
const iv: ArrayBuffer = convertHexToArrayBuffer(payload.iv)
const hmac: ArrayBuffer = convertHexToArrayBuffer(payload.hmac)
const hmacHex: string = convertArrayBufferToHex(hmac, true)
const unsigned: ArrayBuffer = concatArrayBuffers(cipherText, iv)
const chmac: ArrayBuffer = await createHmac(unsigned, key)
const chmacHex: string = convertArrayBufferToHex(chmac, true)
if (removeHexPrefix(hmacHex) === removeHexPrefix(chmacHex)) {
return true
}
return false
}
export async function verifyHmac (
payload: IEncryptionPayload,
key: Buffer
): Promise {
const cipherText: Buffer = convertHexToBuffer(payload.data)
const iv: Buffer = convertHexToBuffer(payload.iv)
const hmac: Buffer = convertHexToBuffer(payload.hmac)
const hmacHex: string = convertBufferToHex(hmac, true)
const unsigned: Buffer = concatBuffers(cipherText, iv)
const chmac: Buffer = await createHmac(unsigned, key)
const chmacHex: string = convertBufferToHex(chmac, true)
if (removeHexPrefix(hmacHex) === removeHexPrefix(chmacHex)) {
return true
}
return false
}