Vuejs 中的代码 -
var message = "Hello World"
var keyBytes = aesjs.utils.utf8.toBytes("akey123")
var iv = CryptoJS.lib.WordArray.random(8).toString()
var ivBytes = aesjs.utils.utf8.toBytes(iv)
var messageBytes = aesjs.utils.utf8.toBytes(message);
var aesCfb = new aesjs.ModeOfOperation.cfb(keyBytes, ivBytes);
var encryptedBytes = aesCfb.encrypt(messageBytes);
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);
我发送给 GO 的数据 -{"iv": iv, "cipher": encryptedHex}
GO中的代码
func DecryptCipher(iv, cipher string) {
key := []byte("akey123")
iv := []byte(iv)
cipherText, _ := hex.DecodeString(cipher)
block, err := aes.NewCipher(key)
if err != nil {
log.Println(err)
}
cfb := cipher.NewCFBDecrypter(block, iv)
cfb.XORKeyStream(cipherText, cipherText)
fmt.Println("data", string(cipherText))
}
预期输出:“Hello World”实际输出:@�Sa 1���Ig{�
有人可以帮助我并告诉我上面的代码中缺少什么。先感谢您!
郎朗坤
相关分类