Skip to content

n.randomBytes is not a function #602

@bradleyhodges

Description

@bradleyhodges

When trying to execute forge.pki.encryptRsaPrivateKey(keypair.privateKey, password); in an Electron app, the exception n.randomBytes is not a function is thrown.

I've double checked, and this issue doesn't occur when executed in a Google Chrome tab. Here's the script I'm using:

var rsa = forge.pki.rsa; var password = "(this is retrieved elsewhere)";
rsa.generateKeyPair({bits: 2048, workers: 2}, function(err, keypair) {
    var publicKey = forge.pki.publicKeyToPem(keypair.publicKey);
    var privateKey = forge.pki.encryptRsaPrivateKey(keypair.privateKey, password);
});

By the looks of it, the exception is occurring when trying to execute the forge.pki.encryptRsaPrivateKey function in Electron.

Here's what the exception looks like in the DevTools:
image

and this is where the exception appears to occur:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions