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":"MvXXXxUzO9kXcP81XzSXd1OnjJ0XkYTaY9pKhHohxrYo40Hf4GLgITwfLDigoPebE2Hmw921\n1JNhM+yk6z3s6VckNcl65xBN4dUlCdd81MnqDlPUq6MzrqtwLqSQLxlCQCHkR7D+4wc5CK/V\nX6yKUOrKdAeXa5pM5lwreKzZtNwT182Y4dcWf279f5cLk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