signature_create | R Documentation |
Sign and verify a message digest. RSA supports both MD5 and SHA signatures
whereas DSA and EC keys only support SHA. ED25591 can sign any payload so you can
set hash
to NULL
to sign the raw input data.
signature_create(data, hash = sha1, key = my_key(), password = askpass)
signature_verify(data, sig, hash = sha1, pubkey = my_pubkey())
ecdsa_parse(sig)
ecdsa_write(r, s)
data |
raw data vector or file path for message to be signed.
If |
hash |
the digest function to use. Must be one of |
key |
private key or file path. See |
password |
string or a function to read protected keys. See |
sig |
raw vector or file path for the signature data. |
pubkey |
public key or file path. See |
r |
bignum value for r parameter |
s |
bignum value for s parameter |
The ecdsa_parse
and ecdsa_write
functions convert (EC)DSA signatures
between the conventional DER format and the raw (r,s)
bignum pair. Most
users won't need this, it is mostly here to support the JWT format (which does not
use DER).
# Generate a keypair
key <- rsa_keygen()
pubkey <- key$pubkey
# Sign a file
data <- system.file("DESCRIPTION")
sig <- signature_create(data, sha256, key = key)
stopifnot(signature_verify(data, sig, sha256, pubkey = pubkey))
# Sign raw data
data <- serialize(iris, NULL)
sig <- signature_create(data, sha256, key = key)
stopifnot(signature_verify(data, sig, sha256, pubkey = pubkey))
# Sign a hash
md <- md5(data)
sig <- signature_create(md, hash = sha256, key = key)
stopifnot(signature_verify(md, sig, hash = sha256, pubkey = pubkey))
#
# ECDSA example
data <- serialize(iris, NULL)
key <- ec_keygen()
pubkey <- key$pubkey
sig <- signature_create(data, sha256, key = key)
stopifnot(signature_verify(data, sig, sha256, pubkey = pubkey))
# Convert signature to (r, s) parameters and then back
params <- ecdsa_parse(sig)
out <- ecdsa_write(params$r, params$s)
identical(sig, out)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.