javascript - Encrypt iOS and Decrypt Node.js AES -


i have searched high , low solution , encrypt on node.js server , objective-c client, , vise versa using aes (or other if appropriate)

i relatively new cryptography, , understanding why encrypted text different in each language beyond knowledge.

this have far:

node.js crypto methods using cryptojs library - node-cryptojs-aes

var node_cryptojs = require("node-cryptojs-aes"); var cryptojs = node_cryptojs.cryptojs;      var texttoencrypt = 'hello'; var key_clear = 'a16byteslongkey!';  //encrypted + decrypted  var encrypted = cryptojs.aes.encrypt(cleartext, key_clear, { iv: null }); var decrypted = cryptojs.aes.decrypt(encrypted, key_clear, { iv: null });  //outputs        console.log("encrypted: " + encrypted);     //encrypted: u2fsdgvkx1/ilxojqiw2vvz6dzrh1lmhgeqhdm3ouny= console.log("decrypted: " + decrypted.tostring(cryptojs.enc.utf8));   // decrypted: hello 

objective-c crypto methods using aescrypt library

nsstring* texttoencrypt = @"hello";  // encrypt nsstring* encryptedtext = [aescrypt encrypt:texttoencrypt password:@"a16byteslongkey!"];  // decrypt nsstring* decryptedtext = [aescrypt decrypt:encryptedtext password:@"a16byteslongkey!"];  // output nslog(@"text encrypt: %@", texttoencrypt);    // text encrypt: hello nslog(@"encrypted text: %@", encryptedtext);     // encrypted text: wy80mjyxrrjde+ekw6kaia== nslog(@"decrypted text: %@", decryptedtext);     // decrypted text: hello 

i've been scratching head ages , tried can think of. can show underlying crypto methods libraries if required. there shar256 hash applied key in aescrypt library have removed this, , think there missmatch string encoding.

  1. are sure same key being used in both libraries? took out sha-256 part in aescrypt, how library using password parameter now? aes algorithm can use keys of 16, 24, or 32 bytes in length. password 16 bytes long, did change corresponding parameter 128 (instead of 256) in encrypt function? know how cryptojs using key parameter? sure it's being used directly, or might there processing (for example, hashing) before it's passed underlying primitive aes encryption function?

  2. what mode of encryption cryptojs library using? documentation doesn't say. given asks iv, it's cbc, have @ source know sure. aescrypt's documentation claims use cbc mode, don't give iv anywhere. must mean generates own somewhere, or uses fixed one. (which half defeats purpose of cbc mode, that's story). need figure out iv is.

tl;dr: unless make sure same key , key length, same mode, , same iv used across both libraries, have different cipher text.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -