keypair_openssl {cyphr} | R Documentation |
Asymmetric encryption with openssl
Description
Wrap a pair of openssl keys. You should pass your private key and the public key of the person that you are communicating with.
Usage
keypair_openssl(
pub,
key,
envelope = TRUE,
password = NULL,
authenticated = TRUE
)
Arguments
pub |
An openssl public key. Usually this will be the path
to the key, in which case it may either the path to a public key
or be the path to a directory containing a file
|
key |
An openssl private key. Usually this will be the path
to the key, in which case it may either the path to a private
key or be the path to a directory containing a file. You may
specify |
envelope |
A logical indicating if "envelope" encryption
functions should be used. If so, then we use
|
password |
A password for the private key. If |
authenticated |
Logical, indicating if the result should be
signed with your public key. If |
See Also
keypair_sodium()
for a similar function using
sodium keypairs
Examples
# Note this uses password = FALSE for use in examples only, but
# this should not be done for any data you actually care about.
# Note that the vignette contains much more information than this
# short example and should be referred to before using these
# functions.
# Generate two keypairs, one for Alice, and one for Bob
path_alice <- tempfile()
path_bob <- tempfile()
cyphr::ssh_keygen(path_alice, password = FALSE)
cyphr::ssh_keygen(path_bob, password = FALSE)
# Alice wants to send Bob a message so she creates a key pair with
# her private key and bob's public key (she does not have bob's
# private key).
pair_alice <- cyphr::keypair_openssl(pub = path_bob, key = path_alice)
# She can then encrypt a secret message:
secret <- cyphr::encrypt_string("hi bob", pair_alice)
secret
# Bob wants to read the message so he creates a key pair using
# Alice's public key and his private key:
pair_bob <- cyphr::keypair_openssl(pub = path_alice, key = path_bob)
cyphr::decrypt_string(secret, pair_bob)
# Clean up
unlink(path_alice, recursive = TRUE)
unlink(path_bob, recursive = TRUE)