How to use CryptoJS with Angular
Everything is in the title. I want to use CrytoJS lib in AngularJS app and I cannot get rid of it.
I am installing crytoJS with gazebo:
bower install cryptojslib
Then I download the lib that I need:
<script type="text/javascript" src="/public/system/lib/cryptojslib/rollups/md5.js"></script>
<script type="text/javascript" src="/public/system/lib/cryptojslib/components/enc-base64-min.js"></script>
And I am trying to use CryptoJS like this:
var pwd = CryptoJS.MD5(params.email+'|'+params.password).toString(CryptoJS.enc.Base64);
When I run this code, I have the following error:
'CryptoJS is not defined'
I've read that it should be possible to wrap CryptoJS in a module, but I don't know how.
Any help would be greatly appreciated.
JM.
+3
source to share
2 answers
There shouldn't be any problem with AngularJS and CryptoJS. I am setting up a fast Plunker that has a hash generated in the controller. No mistakes...
http://plnkr.co/edit/kzrr3EdHNXELVof6DVSp?p=preview
In the controller:
$scope.hash = CryptoJS.MD5("Message");
In HTML:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>
Isn't that how you are trying?
+4
source to share