crypto#generateKeyPair TypeScript Examples

The following examples show how to use crypto#generateKeyPair. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: instructions.ts    From adonis5-jwt with MIT License 6 votes vote down vote up
async function makeKeys(
    projectRoot: string,
    _app: ApplicationContract,
    sink: typeof sinkStatic,
    _state: InstructionsState
) {
    await new Promise((resolve, reject) => {
        generateKeyPair(
            "rsa",
            {
                modulusLength: 4096,
                publicKeyEncoding: {
                    type: "spki",
                    format: "pem",
                },
                privateKeyEncoding: {
                    type: "pkcs8",
                    format: "pem",
                },
            },
            (err, publicKey, privateKey) => {
                if (err) {
                    return reject(err);
                }

                resolve({ publicKey, privateKey });
            }
        );
    }).then(({ privateKey, publicKey }) => {
        const env = new sink.files.EnvFile(projectRoot);
        env.set("JWT_PRIVATE_KEY", privateKey.replace(/\n/g, "\\n"));
        env.set("JWT_PUBLIC_KEY", publicKey.replace(/\n/g, "\\n"));
        env.commit();
        sink.logger.action("update").succeeded(".env,.env.example");
    });
}
Example #2
Source File: gen-keypair.ts    From metroline with GNU General Public License v3.0 5 votes vote down vote up
generateKeyPairAsync = promisify(generateKeyPair)