Generating RSA Public and Private Keys in JScript

58 views Asked by At

Hello Stack Overflow community,

I'm currently working on a project that requires me to generate RSA public and private keys using JScript. After some research, I came across this JavaScript library called JSEncrypt, which provides tools for working with RSA encryption.

However, I'm having trouble replicating the functionality of JSEncrypt in a Windows Scripting environment.

Here's what I've tried so far:

var fso = new ActiveXObject("Scripting.FileSystemObject");
var tempFolder = fso.GetSpecialFolder(2); // get temporary dir

var size = 1024; // RSA key size
var crypt = new JSEncrypt({ default_key_size: size });

function r(key) {
    return key.replace(/\n/g, "");
}

crypt.getKey();

var publicKeyFile = fso.CreateTextFile(tempFolder + "\\public.key");
publicKeyFile.Write(r(crypt.getPublicKey()));
publicKeyFile.Close();

var privateKeyFile = fso.CreateTextFile(tempFolder + "\\private.key");
privateKeyFile.Write(r(crypt.getPrivateKey()));
privateKeyFile.Close();

WScript.Echo("Done!");

I'm looking for guidance on how to implement RSA key generation in the Windows Scripting environment, similar to what JSEncrypt does. Specifically, I need to create RSA public and private keys and save them to files.

Any help, suggestions, or sample code would be greatly appreciated. Thank you in advance for your assistance!

0

There are 0 answers