Please help, I thought this would take 1 hour but now its day 2. There are a few different types of AES see...
I have managed to get CryptoJS to use CTR mode, which is what I usually use on my working decrypt func in go programs.
For this example i'm using the key as iv, as I know this is transmitted with integrity to the go server (just trying to make less room for error)
Still it wont decrypt. I have decoded the base 64 that cryptoJS encodes the ciphertext with first before trying...
Any genius(s) around that can help me with where i'm going wrong?
The iv on the JS side is an object l.WordArray.t.extend.init {words: Array[4], sigBytes: 16, init: function, toString: function, concat: function…}
...and mine is a hex string (although they are both created from the key as i said)
Javascript
function AESencrypt(key, input) {
var key = CryptoJS.enc.Hex.parse(key);
var e = CryptoJS.AES.encrypt(input, key, { mode: CryptoJS.mode.CTR, iv: key });
return(btoa(e));
}
Golang
func ivcrypt(key string, ciphertext []byte) string {
block, err := aes.NewCipher([]byte(key))
if err != nil {
return("CIPHER INIT ERROR")
}
if len(ciphertext) < aes.BlockSize {
return("CIPHERTEXT LENGTH TOO SHORT!")
}
text := decodeBase64(string(ciphertext))
iv := []byte(key)[:aes.BlockSize]
text = text[aes.BlockSize:]
cfb := cipher.NewCFBDecrypter(block, iv)
cfb.XORKeyStream(text, text)
return string(decodeBase64(string(text)))
}