R: Signatures

signature_create {openssl} | R Documentation

## Signatures

### Description

Sign and verify a message digest. RSA supports both MD5 and SHA signatures whereas DSA and EC keys only support SHA.

### Usage

    signature_create(data, hash = sha1, key = my_key(), password = askpass)

    signature_verify(data, sig, hash = sha1, pubkey = my_pubkey())

### Arguments

`data` | raw data vector or file path for message to be signed. If `hash == NULL` then `data` must be a hash string or raw vector.
`hash` | the digest function to use. Must be one of `md5`, `sha1`, `sha256`, `sha512` or `NULL`.
`key` | private key or file path. See `read_key`.
`password` | string or a function to read protected keys. See `read_key`.
`sig` | raw vector or file path for the signature data.
`pubkey` | public key or file path. See `read_pubkey`.

### Examples

    # Generate a keypair
    key <- rsa_keygen()
    pubkey <- key$pubkey

    # Sign a file
    data <- system.file("DESCRIPTION")
    sig <- signature_create(data, key = key)
    stopifnot(signature_verify(data, sig, 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 = NULL, key = key)
    stopifnot(signature_verify(md, sig, hash = NULL, pubkey = pubkey))

[Package openssl version 1.0.1 Index]