node.js hash string?

后端 未结 11 2361
暗喜
暗喜 2020-12-02 03:49

I have a string that I want to hash. What\'s the easiest way to generate the hash in node.js?

The hash is for versioning, not security.

11条回答
  •  暖寄归人
    2020-12-02 04:13

    I use blueimp-md5 which is "Compatible with server-side environments like Node.js, module loaders like RequireJS, Browserify or webpack and all web browsers."

    Use it like this:

    var md5 = require("blueimp-md5");
    
    var myHashedString = createHash('GreensterRox');
    
    createHash(myString){
        return md5(myString);
    }
    

    If passing hashed values around in the open it's always a good idea to salt them so that it is harder for people to recreate them:

    createHash(myString){
        var salt = 'HnasBzbxH9';
        return md5(myString+salt);
    }
    

提交回复
热议问题