Вопрос

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.

Это было полезно?

Решение 2

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"

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top