Integration Crypto-js in typeScript Angular 2

1,833 views
Skip to first unread message

Henri Pollet

unread,
Apr 13, 2016, 11:36:38 AM4/13/16
to AngularJS
Hi , 

In our process to learn Angular2 . we are trying to use api done by  marvel . The access to this api is done with hash key that we need to send to the api
but we don't really know how to implement 
 
On the running process we the error ;. "require is not defined"

Here is the piece of code ;

generateMarvelAccessUrl(baseurl: string) {

        var CryptoJS = require("crypto-js");

        var PRIV_KEY = "mypublickey";
        var API_KEY   = "myprivatekey";

        var url = baseurl + "?limit=100&apikey=" + API_KEY;
        var ts = new Date().getTime();
        var hash = CryptoJS.createHash('md5').update(ts + PRIV_KEY + API_KEY).digest('hex');
        url += "&ts=" + ts + "&hash=" + hash;
        return url;

    }

Is someone may help us on that . 

We are new on angular 2

Regards 

Sander Elias

unread,
Apr 14, 2016, 4:55:44 AM4/14/16
to AngularJS
Hi Henri,

If you are going to do this is the browser, you should be aware that you are exposing your private key on the internet. I don't think this is a good idea. A better idea is to add an API endpoint to your back-end that handles this.
If you want to know more on why, just search this group on security. There are a number of threads that go into more detail on this.

Regards
Sander

Henri

unread,
Apr 14, 2016, 5:28:36 AM4/14/16
to ang...@googlegroups.com

HI

Thanks a lot of for this point !
I really new on web side and i completly Forget this point .

Really appreciate your feed-back 

Regards

Henri
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/WoIpaCqEalM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages