我在@osgx的帮助下解决了这个问题
这些是我需要更改以正确解密的事情。
解码我正在使用的所有十六进制字符串。
我检查了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



