File: pkcs7.R

package info (click to toggle)
r-cran-openssl 2.3.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,336 kB
  • sloc: ansic: 3,158; sh: 20; makefile: 5
file content (38 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download
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
#' Encrypt/decrypt pkcs7 messages
#'
#' Encrypt or decrypt messages using PKCS7 smime format.
#' Note PKCS7 only supports RSA keys.
#'
#' @export
#' @rdname pkcs7
#' @useDynLib openssl R_pkcs7_encrypt
#' @param message text or raw vector with data to encrypt
#' @param cert the certificate with public key to use for encryption
#' @param pem convert output pkcs7 data to PEM format
pkcs7_encrypt <- function(message, cert, pem = TRUE){
  if(is.character(cert))
    cert <- read_cert(cert)
  if(is.character(message))
    message <- charToRaw(message)
  out <- .Call(R_pkcs7_encrypt, message, cert)
  if(!isTRUE(pem)){
    return(out)
  }
  write_pem(out)
}

#' @export
#' @rdname pkcs7
#' @seealso [encrypt_envelope]
#' @param input file path or string with PEM or raw vector with p7b data
#' @param key private key to decrypt data
#' @param der assume input is in DER format (rather than PEM)
#' @useDynLib openssl R_pkcs7_decrypt
pkcs7_decrypt <- function(input, key, der = is.raw(input)){
  if(length(key)) key <- read_key(key)
  buf <- read_input(input)
  if(!isTRUE(der)){
    buf <- parse_pem_pkcs7(buf)
  }
  .Call(R_pkcs7_decrypt, buf, key)
}