The keygen functions generate a random private key. Use as.list(key)$pubkey
to derive the corresponding public key. Use write_pem to save a private key
to a file, optionally with a password.
Usage
rsa_keygen(bits = 2048)
dsa_keygen(bits = 1024)
ec_keygen(curve = c("P-256", "P-384", "P-521"))
x25519_keygen()
ed25519_keygen()Examples
# Generate keypair
key <- rsa_keygen()
pubkey <- as.list(key)$pubkey
# Write/read the key with a passphrase
write_pem(key, "id_rsa", password = "supersecret")
read_key("id_rsa", password = "supersecret")
#> [2048-bit rsa private key]
#> md5: d85445a6134f2e86f2c43470f888bc38
#> sha256: b739404480e150466bf8e24cf8d5c655e76f4f9cc97a9961268a19667b6ad19c
unlink("id_rsa")