Empowering you to understand your world

TypeError: crypto.scryptSync is not a function

If you were using the Crypto library in Node.js to encrypt a string, you may have encountered the ‘scryptSync is not a function’ error. This can occur even if you copy a code sample directly from the Node.js website’s official Crypto library documentation.

Others have encountered this issue and it is because ‘scryptSync‘ is available only on Node.js versions later than 10. If you’re on Ubuntu 18.04, you might be getting Node version 8.10.x from the Ubuntu distribution channel/repository as the ‘latest’ version.

Upgrading to Node.js version 10.16.0 resolved the issue for me.

This is the code I was using when the issue occurred (obtained with thanks from the official Node Crypto documentation):

 const crypto = require('crypto');

    const algorithm = 'aes-192-cbc';
    const password = 'Password used to generate key';
    const key = crypto.scryptSync(password, 'salt', 24);

    const iv = Buffer.alloc(16, 0); 
    const cipher = crypto.createCipheriv(algorithm, key, iv);
    let encrypted = cipher.update('some clear text data', 'utf8', 'hex');
    encrypted += cipher.final('hex');

If you’re on Windows, you can install Node 10.16 by downloading it from the official Node.js website. If you’re on Ubuntu, the simple upgrade requires only three steps.

Subscribe to our newsletter
Get notified when new content is published