0

I have an encrypted text message and I want to decrypt it using "crypto-js" library posted on the link: http://code.google.com/p/crypto-js/

I want to decrypt using TRIPLE DES. I downloaded the library and placed "tripledes.js" under "lib" folder in my project. And I'm calling the function to decrypt in this way:

var lib_decrypt = require('tripledes');
var message = lib_decrypt.DES.decrypt(Ti.Utils.base64decode(thetext), "secretphrase");
alert(message);

I'm always getting this error: "Cannot call method 'decrypt' of undefined".

I checked up "tripledes.js" code and sincerely its a big library so i didn't find a solution for how to use this library to decrypt my text in Titanium.

Thank you in advance.

Anthony
  • 189
  • 1
  • 3
  • 16

2 Answers2

1

Maybe the error is your object have you tried to create an instance or an object of "tripledes"

 var decode = require('tripledes');
 var test = new decode();
 var message = test.DES.decrypt(Ti.Utils.base64decode(thetext), "secretphrase");

also have you checked that tripledes.js is in order with the CommonJS Modules in Titanium? https://wiki.appcelerator.org/display/guides/CommonJS+Modules+in+Titanium

Mario Galván
  • 3,964
  • 6
  • 29
  • 39
  • Dear @Mayito, no its not a problem of instantiating. The problem was occured because I missed to put "exports.CryptoJS = CryptoJS;" in "tripledes.js". Anyway thank you very much for your help because your link is very helpful – Anthony Mar 13 '13 at 07:08
1

The problem was occured because I missed to export "CryptoJS" in "tripledes.js". So when I put "exports.CryptoJS = CryptoJS;" in "tripledes.js", everything works fine because all tripledes library functions are related to the instance of "CryptoJS"

Anthony
  • 189
  • 1
  • 3
  • 16