Last data update: 2014.03.03

R: PKI: sign content or verify a signature
PKI.signR Documentation

PKI: sign content or verify a signature

Description

PKI.sign signs content using RSA with the specified hash function

PKI.verify verifies a signature of RSA-signed content

Usage

PKI.sign(what, key, hash = c("SHA1", "SHA256", "MD5"), digest)
PKI.verify(what, signature, key, hash = c("SHA1", "SHA256", "MD5"), digest)

Arguments

what

raw vector: content to sign

key

RSA private key to use for signing; RSA public key or certificate to use for verification.

hash

hash function to use. "MD5" should not be used unless absolutely needed for compatibility as it is less secure.

digest

raw vector: it is possible to supply the digest of the content directly instead of specifying what.

signature

raw vector: signature

Details

Objects are signed by computing a hash function digest (typically using SHA1 hash function) and then signing the digest with a RSA key. Verification is done by computing the digest and then comparing the signature to the digest. Private key is needed for signing whereas public key is needed for verification.

Both functions call PKI.digest on what if digest is not specified.

Value

PKI.sign signature (raw vector)

PKI.verify logical: TRUE if the digest and signature match, FALSE otherwise

Author(s)

Simon Urbanek

See Also

PKI.pubkey, PKI.genRSAkey, PKI.digest

Examples

  key <- PKI.genRSAkey(2048)
  x <- charToRaw("My message to sign")
  sig <- PKI.sign(x, key)
  stopifnot(PKI.verify(x, sig, key))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(PKI)
Loading required package: base64enc
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/PKI/PKI.sign.Rd_%03d_medium.png", width=480, height=480)
> ### Name: PKI.sign
> ### Title: PKI: sign content or verify a signature
> ### Aliases: PKI.sign PKI.verify
> ### Keywords: manip
> 
> ### ** Examples
> 
>   key <- PKI.genRSAkey(2048)
>   x <- charToRaw("My message to sign")
>   sig <- PKI.sign(x, key)
>   stopifnot(PKI.verify(x, sig, key))
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>