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":"zU8/3MBOf/NRF/knjkDv2m24LH9TBcDn+FCnCTyLLNQRnd4TKq1auN/cMbmlW8KsBmRikZk5\n9yWpD1iG7AMNWimH64gJVWW/2FACst4bdXnn+kf3HHz3vuM5dNPafDwbKTNQGdz7AgZAnpyr\n3Hcg+D1/3vZGyjOSA8bD716/aS3cdT4yASfe6vBWLBM2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