Generate a deterministic RSA keypair from a seed (any string) and get back a CryptoKeyPair
. The keypair will always be the same for the same input string.
It relies on node-forge and is based roughly on this StackOverflow post.
import { generateSeededRsa } from 'https://gitlab.com/soapbox-pub/seeded-rsa/-/raw/v1.0.0/mod.ts';
const keys = await generateSeededRsa('[email protected]:benis911', { bits: 2048 });
const message = new TextEncoder().encode('hello world!');
const signature = await window.crypto.subtle.sign(
'RSASSA-PKCS1-v1_5',
keys.privateKey,
message,
);
const valid = await crypto.subtle.verify(
'RSASSA-PKCS1-v1_5',
keys.publicKey,
signature,
message,
);
assert(valid); // true
These options may be passed to generateSeededRsa()
:
bits
: Strength of the key, eg2048
,4096
, etc. The default is4096
which is very secure but is SLOW. Using a smaller number like1024
will be fast, but less secure. See here for advice on which bit size to use: https://stackoverflow.com/a/589850
This is free and unencumbered software released into the public domain.