编码AES在Go和解码在CryptoJS
Encoding AES in Go and Decoding in CryptoJS
我在Go中有这些:
var commonIV = []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
plaintext := []byte("hello, world")
key_text := "32o4908go293hohg98fh40gh"
c, err := aes.NewCipher([]byte(key_text))
if err != nil {
fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key_text), err)
return
}
cfbdec := cipher.CBCEncrypter(c, commonIV)
ciphertext := make([]byte, len(plaintext))
cfbdec.CryptBlock(ciphertext, plaintext)
fmt.Printf("%x", ciphertext) //HEX
输出:e0df84c3b83681a8133e1787
和I导入以下url:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/mode-cfb-min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1/build/components/pad-nopadding.js"></script>
和我在JS中的代码如下:
var data = CryptoJS.enc.Hex.parse("e0df84c3b83681a8133e1787");
console.log(data);
var key = "32o4908go293hohg98fh40gh";
var iv = CryptoJS.enc.Base64.parse("AAAAAAAAAAAAAAAAAAAAAA==");
console.log(iv);
var encrypted = {};
encrypted.key=key;
encrypted.iv=iv;
encrypted.ciphertext = data;
var dec = CryptoJS.AES.decrypt(encrypted, key, { mode: CryptoJS.mode.CFB, iv: iv, padding: CryptoJS.pad.NoPadding });
console.log(dec);
console.log(dec.toString());
console.log(dec.toString(CryptoJS.enc.Utf8));
我做错了什么?
看起来你在Go中使用CBCEncrypter
(块计数器模式),但在JS代码中使用CryptoJS.mode.CFB
(密码反馈模式)。据我所知,这些都不是兼容的块模式。
你不想在Go代码中使用CBCEncrypter吗?
相关文章:
- 在文本区域POST后解码JSON
- CryptoJS和密钥/IV长度
- Json字符串可以'当字符串末尾有“'时,t解码;
- 有没有一种方法可以在没有文档或jQuery的情况下使用javascript解码html实体
- 如何在JS中获得CryptoJS.HmacSHA256的摘要表示
- 从Base64 Ionic编码和解码图像
- 如何在JS中编码URL并在PHP中解码
- 在服务器中编码,并使用escape在javascript中解码
- 如何编码/解码这个专有校验和(Athena 16C PID控制器)
- php中javascript解码中的base64编码
- 在Erlang中解码URIComponent
- AngularJs正在解码HTML字符(不需要)
- 隐藏HTML元素中的JSON编码和解码
- 将Base64音频文件Mp3解码为可播放的Mp3
- AES-CTR 在 Go 中加密,在 CryptoJS 中解密
- 如何使用Java解码由window.btoa编码的base64图像
- 如何将HMAC添加到CryptoJS AES加密中
- 标题不适用于解码URIComponent和空格
- 为什么我不必在 JS 中解码/解析 PHP 生成的 JSON 字符串
- 编码AES在Go和解码在CryptoJS