Golang AES-CBC 256使用CryptoJS解密
发布时间:2020-12-16 09:26:13 所属栏目:大数据 来源:网络整理
导读:已经工作了几天试图让Golang AES-CBC工作(或反之亦然),我修复了大部分错误但没有得到解密,即使我已经确认密钥,iv,密文在两端是相同的. 必须有人知道,网上任何地方都没有工作的例子…… //golang if a == "test64bytes" { output = "AAAAAAAABBBBBBBBCCCCCCCC
已经工作了几天试图让Golang AES-CBC工作(或反之亦然),我修复了大部分错误但没有得到解密,即使我已经确认密钥,iv,密文在两端是相同的.
必须有人知道,网上任何地方都没有工作的例子…… //golang if a == "test64bytes" { output = "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD" } // encrypt ajax response iv := decodeBase64("AAAAAAAAAAAAAAAAAAAAAA==") ciphertext := []byte(output) ckey := decodeBase64(string(PLAINkey[0:32])) c,err := aes.NewCipher(ckey) cfbdec := cipher.NewCBCDecrypter(c,iv) plaintext := make([]byte,len(ciphertext)) cfbdec.CryptBlocks(plaintext,ciphertext) crypt := string(encodeBase64(plaintext)) fmt.Fprintf(res,"%v",crypt) fmt.Println(encodeBase64(ckey)) fmt.Println(encodeBase64(iv)) fmt.Println(crypt) // javascript if (xmlhttp.readyState==4 && xmlhttp.status==200) { var enc = {}; enc["key"] = CryptoJS.enc.Base64.parse(keyseed.substring(0,32)); enc["iv"] = CryptoJS.enc.Base64.parse("AAAAAAAAAAAAAAAAAAAAAA=="); enc["ciphertext"] = CryptoJS.enc.Base64.parse(xmlhttp.responseText); enc["salt"] = ""; console.log("RESPONSE:",xmlhttp.responseText,atob(xmlhttp.responseText)); // check i'm using same data console.log(CryptoJS.enc.Base64.stringify(enc["key"])); console.log(CryptoJS.enc.Base64.stringify(enc["iv"])); console.log(CryptoJS.enc.Base64.stringify(enc["ciphertext"])); var options = { keySize: 256 / 8,mode: CryptoJS.mode.CBC,padding: CryptoJS.pad.Pkcs7,iv: enc["iv"] }; de = CryptoJS.AES.decrypt(enc,enc["key"],options); document.getElementById(target).innerHTML = de.toString(); console.log(de.toString(CryptoJS.enc.Utf8)); console.log("DECRYPTION FINISHED"); } 解决方法
在有条不紊地尝试所有可能的AES配置后,我现在可以解密我的文本..
…在本例中使用空白iv(“AAAAAAAAAAAAAAAAAAAAAA ==”).如果你使用另一个,它将成为加密时的第一个明文块… 去> CryptoJS // 走 plaintext := []byte("THIS NEEDS TO BE MULTIPLE OF BLOCK LENGTH (16) I THINK") // encrypt ajax response iv := decodeBase64("AAAAAAAAAAAAAAAAAAAAAA==") ckey := decodeBase64(string(PLAINkey[0:32])) c,err := aes.NewCipher(ckey) cfbdec := cipher.NewCBCEncrypter(c,iv) ciphertext := make([]byte,len(plaintext)) cfbdec.CryptBlocks(ciphertext,plaintext) crypt := string(encodeBase64(ciphertext)) fmt.Fprintf(res,crypt) // JavaScript Ajax if (xmlhttp.readyState==4 && xmlhttp.status==200) { var symkey = keyseed.substring(0,32); var cipherParams = CryptoJS.lib.CipherParams.create({ ciphertext: CryptoJS.enc.Base64.parse(xmlhttp.responseText) }); var options = { mode: CryptoJS.mode.CBC,padding: CryptoJS.pad.NoPadding,iv: CryptoJS.enc.Base64.parse("AAAAAAAAAAAAAAAAAAAAAA==") }; de = CryptoJS.AES.decrypt(cipherParams,CryptoJS.enc.Base64.parse(symkey),options); document.getElementById(target).innerHTML = de.toString(CryptoJS.enc.Utf8); console.log("DECRYPTION FINISHED"); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |