by
82k 39
8
10
39k
458
Top 1% !
Popular
Famous
Pearl of Wisdom
Nice
Tagged
Easy-to-find
Specified
Debate
OpenSource
Popularity: 61st place

Published on:

Frameworknode.js
Languagetypescript
LicenseMIT_X11

Using crypto-js in node.js with Typescript

You can easily install the crypto-js library in node by using the command (on Mac):
> npm install crypto-js

After that you need to download its type definition from Git/DefinitelyTyped:
https://github.com/borisyankov/DefinitelyTyped/tree/master/cryptojs

To make it work, however you need to add the following to the cryptojs.d.ts:
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/28724/Using-crypto-js-in-node-js-with-Typescri?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// add this at the end of crypto.d.ts declare module "crypto-js" { export = CryptoJS; } // Then you can use the module in typescript ///<reference path='../types/node.d.ts'/> ///<reference path='../types/cryptojs.d.ts'/> import crypto = require("crypto-js"); function writeln( msg: string ) { process.stdout.write( msg +'\n'); } var message : string = "Hello Encrypted World!"; var cmessage : string = crypto.HmacSHA1( message , "1234").toString(); writeln( message ); writeln( cmessage );
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus