Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23291] Windows: Random Values while trying to decrypt value using AES encryption on device

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2017-10-19T07:15:52.000+0000
Affected Version/sRelease 5.2.0
Fix Version/sRelease 7.0.0
ComponentsWindows
Labels8.1, AES, alloy, decryption, encryption
ReporterParmeet Singh
AssigneeKota Iguchi
Created2016-04-12T15:17:16.000+0000
Updated2018-08-06T17:49:25.000+0000

Description

I am trying to implement encryption in my app for Windows Phone 8.1, it successfully encrypts the value but when I try to decrypt the same value it is generating random values every time. Below is the code I am using for encryption and decryption.

var CryptoJS = require('aes').CryptoJS;


function encrypt(input) {
	var encrypted = CryptoJS.AES.encrypt(input, "12345");
	return encrypted;
}


function decrypt(input) {
	var decrypted = CryptoJS.AES.decrypt(input, "12345").toString(CryptoJS.enc.Utf8);
	return decrypted;
}

var devId = Ti.Platform.id;
alert("DevID : "+devId);
var encr = encrypt(devId);
alert("encr : "+encr);

alert("decr : "+decrypt(encr));


P.S : When I run this app on emulator it is correctly decrypting the vales but when I try same app on device I am facing the above stated problem.

Comments

  1. Nazmus Salahin 2016-04-13

    Hello, Thanks for sharing the issue with us. It will be helpful for us to identify the problem if you share the source of the 'aes' module that you are using. Regards
  2. Parmeet Singh 2016-04-13

    Hi Nazmus, I have used below links for AES : http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core-min.js http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-utf16-min.js http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js P.S : We have used same AES method for iOS and Android and its working fine on them even it works well with windows phone emulator.
  3. Nazmus Salahin 2016-04-17

    Hello [~paramsb], I guess you have made your own module from those file and accessed that as follows.
       var CryptoJS = require('aes').CryptoJS;
       
    Please give us your code of the module so that we can test your code and find the actual reason for this inconvenience. Thanks in advance
  4. Parmeet Singh 2016-04-21

    Dear Nazmus Salahin, Thanks for responding. I am not creating any module, I have just created a new file under lib folder as 'AES' and have used the codes from the above listed libs and then I am calling the lib and using the encrypt & decrypt function.
  5. Nazmus Salahin 2016-04-21

    Hello, Please share that file with us. Thanks in advance
  6. Parmeet Singh 2016-04-21

    Hello Nazmus, We have already shared the file link. Since Appcelerator does not have AES Module, we have used google AES library and required those file. Under lib folder we have included below files : http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core-min.js http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-utf16-min.js http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js At index page we are requiring : var CryptoJS = require('aes').CryptoJS; And we are using it in below function : function encrypt(input) { var encrypted = CryptoJS.AES.encrypt(input, "12345"); return encrypted; } function decrypt(input) { var decrypted = CryptoJS.AES.decrypt(input, "12345").toString(CryptoJS.enc.Utf8); return decrypted; }
  7. Nazmus Salahin 2016-04-25

    Hello [~paramsb], I am not able to reproduce this issue with your given step. If you can provide us with reproducible test code and test step it will be possible for us to test the issue. Thanks
  8. Nazmus Salahin 2016-04-27

    Hello, I am able to reproduce this issue. Encryption and decryption works fine on emulator but not on real device. *Steps:* 1. Download the project from [Google Drive](https://drive.google.com/open?id=0B_1-iP4yRzEsODV4SUxGWHp0Yjg) 2. Import the project. 3. Build and run the app on Windows Phone real device >> Random value is generated after each decryption as seen in alerts. 4. Build and run the app on Windows Phone emulator >> Correct value is produced after decryption. Thanks *Environment*: *Device info:* Windows Phone Emulator and Microsoft Lumia 640 (Windows Phone 8.1) *Node.js Version:* 0.12.7 *npm Version:* 2.11.3 *Titanium SDKs:* 5.2.2.GA and 5.2.1.GA *Java Development Kit Version:* 1.8.0_73 *Titanium CLI Version:* 5.0.5 *Appcelerator CLI Version:* 5.2.2 *Appcelerator Studio:* 4.5.0
  9. Parmeet Singh 2016-05-06

    Hello Nazmus, Just want to know when can I expect the bug to be resolved as I am waiting to implement it and publish. Thanks
  10. Kota Iguchi 2016-05-09

    I have started looking into this recently. I was able to reproduce this on my device too, this ticket is scheduled to 5.4.0 release and I hope we can resolve this until then...
  11. Kota Iguchi 2016-05-10

    I think we hit a bug in JavaScript engine (JavaScriptCore) that we are using. I saw several people reported CryptoJS doesn't work on Safari and Chrome. Is there any way to workaround this? https://github.com/Runscope/crypto-js/issues/80 https://code.google.com/archive/p/crypto-js/issues/72 https://bugs.chromium.org/p/chromium/issues/detail?id=173907
  12. Parmeet Singh 2016-05-18

    Hi Nazmus, Kota, Thanks for your efforts. kindly update us on when we can expect the bug to be resolved. Regards, Parmeet Singh.
  13. Christopher Williams 2016-05-18

    The bug appears to have been fixed in V8, but I don't see any activity on fixes for JavaScriptCore itself, so I have no idea when we'll be able to updated our JSC port with a fix. As a result, this has to get pulled from 5.4.0.
  14. Kota Iguchi 2017-10-19

    Confirmed that this issue is fixed in upcoming Titanium SDK 7.0.0 nightly build. Note that the sample code in the description is obsolete, I used the sample in the latest [crypto-js](https://github.com/brix/crypto-js) to verify.
  15. Eric Merriman 2018-08-06

    Cleaning up older fixed issues. If this issue should not have been closed as fixed, please reopen.

JSON Source