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":"XTDysvbIQy68v23lOwabjVZsXnFidnGbSxMm5qsPgwUqu9uDBrL/V5TrFYyQw0p1ivhYVxd9\nQqcXlWx5l69PGSF7j5l0QzHZ5sicqH+CedIVTB/deUwn1ZPPg7Lv6GqpjH8t1Ivq8tpVNA+e\nSgWzr9ESUHnwrKIuYLRD7NJK21baCLUEr6pzY0kI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