File: keygen.Rd

package info (click to toggle)
r-cran-sodium 1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,680 kB
  • sloc: ansic: 329; sh: 53; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 2,089 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/keygen.R
\name{Key generation}
\alias{Key generation}
\alias{keygen}
\alias{pubkey}
\title{Keypair Generation}
\usage{
keygen(seed = random(32))

pubkey(key)
}
\arguments{
\item{seed}{random data to seed the keygen}

\item{key}{private key for which to calculate the public key}
}
\description{
Functions to generate a random private key and calculate the corresponding curve25519
public key.
}
\details{
Asymmetric methods rely on public-private keypairs. The private keys are secret and
should never be shared with anyone. The public key on the other hand is not confidential
and should be shared with the other parties. Public keys are typically published on the
users's website or posted in public directories or keyservers.

The two main applications for public key cryptography are encryption and authentication.

In public key encryption, data that is encrypted using a public key can only be
decrypted using the corresponding private key. This allows anyone to send somebody a
secure message by encrypting it with the receivers public key. The encrypted message
will only be readable by the owner of the corresponding private key. Basic encryption
is implemented in \link{simple_encrypt}.

Authentication works the other way around. In public key authentication, the owner of the
private key creates a 'signature' (an authenticated checksum) for a message in a way that
allows anyone who knows the user's public key to verify that this message was indeed signed
by the owner of the private key.

If both sender and receiver know each other's public key, the two methods can be combined
so that each message going back and forth is signed by the sender and encrypted for the
receiver. This protects both against eavesdropping and MITM tampering, creating a fully
secure channel.
}
\examples{
# Create keypair
key <- keygen()
pub <- pubkey(key)

# Basic encryption
msg <- serialize(iris, NULL)
ciphertext <- simple_encrypt(msg, pub)
out <- simple_decrypt(ciphertext, key)
stopifnot(identical(msg, out))
}