Note that there are some explanatory texts on larger screens.

plurals
  1. POCryptoJS.AES and Golang
    primarykey
    data
    text
    <p>i already managed to share a random symetric key via rsa. However i fail to make aes-encryption work with it. Problem seems to be the salt and initialization vector, that cryptoJS uses.</p> <p>First it's output is along the lines of:</p> <pre><code>U2FsdGVkX19wbzVqqOr6U5dnuG34WyH+n1A4PX9Z+xBhY3bALGS7DOa/aphgnubc </code></pre> <p>Googling for the reoccuring "U2FsdGVkX" or "cryptoJS.AES output" sadly is of no use.</p> <p>On the other hand, golang's aes requires only a 32bit key and input of 32bit length each. Which means i have to somehow split the above into the corresponding blocks and figure out, how to create the 32bit key out of the secret key and the data above (which proably includes salt + init vector).</p> <p>Sadly neither <a href="http://code.google.com/p/crypto-js" rel="nofollow">http://code.google.com/p/crypto-js</a> nor any google search provide me with a solution.</p> <p>By the way - my encryption right now:</p> <pre><code>var arr = new Array(32); symetricKey = ""; var symHex = ""; rng.nextBytes(arr); for(var i = 0; i &lt; arr.length; i++){ symetricKey += String.fromCharCode(arr[i]); //symHex= arr[i].toString(16), added a 0 if needed (so length always increases by 2) } //submit symetric via rsa. This is working, the server gets that key var enc = CryptoJS.AES.encrypt(unencrypted, symetricKey) //submit enc, stuck now - what to do with it on the server? </code></pre> <p><br> <strong>Edit:</strong> After the Base64 response:<br> Thanks for the base64 input.<br> However i still don't manage to bring it to work. <br>Especially since the encoded string starts with "SALTED", i believe, that there might be a problem.</p> <p>Way i try to encode now:<br> Encoded on Client by:<br></p> <pre><code>var unencrypted = "{mail:test,password:test}" var enc = CryptoJS.AES.encrypt(unencrypted, symKey) </code></pre> <p>On Server, the variables enc and symKey are the same as on Client:</p> <pre><code>baseReader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(enc)) encData, err := ioutil.ReadAll(baseReader) //if err != nil { ....}, doesn't happen here cipher, err := aes.NewCipher(symKey) //if err != nil { ....}, doesn't happen here byteData := make([]byte, len(encData)) cipher.Decrypt(byteData, encData) fmt.Println("Dec: ", string(byteData)) //Outputs unrepresentable characters </code></pre> <p>Any idea?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload