Securely transfer any R object with full attribute preservation and cross-platform JSON compatibility. This uses the same approach as the mmbi.epi package of the UMCG.

post_data(
  object,
  url,
  authorization_header = NULL,
  compress = TRUE,
  encrypt = TRUE,
  key = read_secret("tools.encryption_password")
)

create_json_body(
  object,
  compress = TRUE,
  encrypt = TRUE,
  key = read_secret("tools.encryption_password")
)

Arguments

object

Any object of any size, preferably a data set

url

A character string specifying the target URL for the HTTP POST request. Must include the full scheme (e.g., "https://" or "http://"), hostname, and path.

authorization_header

A character string specifying the value of the Authorization header to include in the POST request, e.g. "Bearer <token>". Use NULL to omit the header.

compress

Should the object be compressed/decompressed? At least allowed: "gzip" (or TRUE), "bzip2", "xz", see base::memCompress(). Use FALSE to not compress/decompress.

encrypt

Should the object be encrypted/decrypted? This applies AES-GCM via openssl::aes_gcm_encrypt(), providing authenticated encryption. This guarantees both confidentiality and integrity: the file cannot be read without the correct key, and any tampering will be detected automatically during decryption. The initialization vector (iv) will be a length-12 random raw vector.

key

A character to be used as the encryption key. Internally, this is converted using openssl::sha256() to ensure a raw high-entropy key of length 32, suitable for AES-GCM encryption. The default is the system environment variable: mmbi_epi_encryption_key.

Examples

if (FALSE) { # \dontrun{

post_data(iris,
          url = "https://some-server:8000/post",
          compress = TRUE,
          encrypt = TRUE)
} # }

# MANUAL WAY -----------------------------------------------------------

# use create_json_body() to make a(n encrypted) JSON of an object

iris_json <- iris |> create_json_body(compress = TRUE, encrypt = TRUE)
#> Warning: In read_secret(): environmental variable 'secrets_file' not set

# curl -X POST https://some-server:8000/post
#      -H "Content-Type: application/json"
#      -d '...'

# replace the "..." with the outcome of create_json_body():
iris_json
#> {"data":"v69fe0Dg58MB0k4OXI6nA8P1e4+4UsfJ5JqF6qSHv+wCUx6qSKIe186lh3kKNX/vGbPx8fWv\nKm8SGUfpmp8b/wkAidiCr27AwnY8xnYosUxjOjuoaqPChOfYGhQmUdN6eOh3EpSP/eQf2sT8\ni7sw47i1VncleAomRJ1AFnhfLey+iZZo/uwEmRIofCRm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