亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用Go編碼AES并使用CryptoJS解碼

使用Go編碼AES并使用CryptoJS解碼

Go
一只斗牛犬 2021-05-20 18:09:40
我在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然后導入以下網址:<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));我做錯了什么?
查看完整描述

2 回答

?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

看起來您CBCEncrypter在Go中使用了(塊計數器模式),但是CryptoJS.mode.CFB在JS代碼中使用了(密碼反饋模式)。據我所知,這些不是兼容的塊模式。


查看完整回答
反對 回復 2021-05-31
?
慕俠2389804

TA貢獻1719條經驗 獲得超6個贊

您是否不想在Go代碼中使用CBCEncrypter?


查看完整回答
反對 回復 2021-05-31
  • 2 回答
  • 0 關注
  • 289 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號