如何解密 HMAC? [英] How can I decrypt a HMAC?
本文介绍了如何解密 HMAC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用以下方法制作 HMAC:
I can make an HMAC using the following:
var encrypt = crypto.createHmac("SHA256", secret).update(string).digest('base64');
我正在尝试使用密钥解密编码的 HMAC:
I am trying to decrypt an encoded HMAC with the secret:
var decrypt = crypto.createDecipher("SHA256", secret).update(string).final("ascii");
以下操作不成功.如何使用密钥解密 HMAC?
The following was unsuccessful. How can I decrypt a HMAC with the key?
我收到以下错误:
node-crypto : Unknown cipher SHA256
crypto.js:155
return (new Decipher).init(cipher, password);
^
Error: DecipherInit error
推荐答案
HMAC 是 MAC/keyed hash,而不是密码.它不是为解密而设计的.如果您想加密某些内容,请使用密码(例如 AES),最好使用经过身份验证的模式(例如 AES-GCM).
HMAC is a MAC/keyed hash, not a cipher. It's not designed to be decrypted. If you want to encrypt something, use a cipher, like AES, preferably in an authenticated mode like AES-GCM.
解密"的唯一方法是猜测整个输入,然后比较输出.
The only way to "decrypt" is guessing the whole input and then comparing the output.
这篇关于如何解密 HMAC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文