栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何解密在nodejs中加密的golang中的AES256位密码?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何解密在nodejs中加密的golang中的AES256位密码?

我在@osgx的帮助下解决了这个问题

这些是我需要更改以正确解密的事情。

  1. 解码我正在使用的所有十六进制字符串。

  2. 我检查了nodejs文档,并且密码方法/算法使用与相似的命名方案

    openssl
    。因此,我运行了此命令,
    openssl list-cipher-algorithms | grep "AES256"
    并得到了这样的输出,
    AES256 => AES-256-CBC
    这意味着,如果我
    aes256
    在nodejs中使用它,它的确会这样做
    aes-256-cbc
    。然后我检查了golang代码,发现使用的
    aes-256-cfb
    是错误的代码。因此,我改变了这一点,并使用了cbc解密器。

更改这两件事可以得到正确的结果。

非常感谢@osgx的帮助。

我更新的代码是:

package mainimport (    "crypto/aes"    "crypto/cipher"    "encoding/hex"    "fmt")func main() {    encKey := "c38036f65157cb6db0e8fd855aa28ada074be71917d1c8eedc2ae4d85e3c9da6"    iv := "79b67e539e7fcaefa7abf167de5c06ed"    cipherText := "c02eccfc514a0b7fae830586dd56e0fcebb81fc49f41fa6dedf099c3645793bef7ec7075eca30063f9c0ef395d5ee2d44e4f3490114280abb7cf86d6eb525e2ec9bd2b781388986480f8b3df95f7b10e"    encKeyDepred, err := hex.DepreString(encKey)    if err != nil {        panic(err)    }    cipherTextDepred, err := hex.DepreString(cipherText)    if err != nil {        panic(err)    }    ivDepred, err := hex.DepreString(iv)    if err != nil {        panic(err)    }    block, err := aes.NewCipher([]byte(encKeyDepred))    if err != nil {        panic(err)    }    mode := cipher.NewCBCDecrypter(block, []byte(ivDepred))    mode.CryptBlocks([]byte(cipherTextDepred), []byte(cipherTextDepred))    fmt.Println(string(cipherTextDepred))}

https://play.golang.org/p/Zv24WoKtBY



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/436334.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号