NodeJs Crypto error -Object has no method pbkdf2Sync

前端 未结 1 559
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-22 06:15

I am using nodeJS Crypto Module to encrypt password.

Sample code:

crypto.pbkdf2Sync(password, salt, 200, 64).toString(\'base64\');         


        
相关标签:
1条回答
  • 2020-12-22 07:12

    pbkdf2Sync was added to the Crypto module in version 0.9.3.

    You can either upgrade your installation of Node to 0.9.3 or higher, or you can use the asynchronous version of the function, crypto.pbkdf2, which requires a callback.

    If your previous code looked like

    var result = crypto.pbkdf2Sync(password, salt, 200, 64);
    var encodedResult = result.toString('base64');
    doStuff(encodedResult);
    

    Then the asynchronous code might look like:

    crypto.pbkdf2Sync(password, salt, 200, 64, function(err, result) {
        var encodedResult = result.toString('base64');
        doStuff(encodedResult);
    });
    

    This is merely an example; a full discussion of sychronous versus asynchronous operations is vastly outside the scope of this question. One good overview of the topic is How do I return the response from an asynchronous call?

    0 讨论(0)
提交回复
热议问题