1 回答

TA贡献2021条经验 获得超8个赞
看起来您需要将您的key和text字符串正确解码为字节切片,而不仅仅是转换它们。下面的代码有效,虽然我不确定解码后的消息应该是什么样子......
package main
import (
"encoding/hex"
"encoding/base64"
"crypto/cipher"
"crypto/sha256"
"crypto/aes"
)
func main() {
iv := "Vmr-uU5mA2_Zr_13"
key := "<Secret_Key>"
ciphertext := "bvtkHfZiTsY0CX6QmHhCboBwXeY9RZVPpdhhdIy6aSwCTVI7YiEGha1aXTIKY4BocGdNIbWkreQHZcTk4WE6F2tQLoVyWERYCGZotbDzxxs="
hash := sha256.Sum256([]byte(key))
key = hex.EncodeToString(hash[:])[:32]
btext, err := base64.StdEncoding.DecodeString(ciphertext)
if err != nil {
println("Error decoding cipertext: ", err.Error())
return
}
aesCipher, err := aes.NewCipher([]byte(key))
if err != nil {
println("Error creating cipher: ", err.Error())
return
}
cipher.NewCBCDecrypter(aesCipher, []byte(iv)).
CryptBlocks(btext, btext)
println("Result: ", string(btext))
}
- 1 回答
- 0 关注
- 145 浏览
添加回答
举报