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")
)Any object of any size, preferably a data set
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.
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.
Should the object be compressed/decompressed? At least allowed: "gzip" (or TRUE), "bzip2", "xz", see base::memCompress(). Use FALSE to not compress/decompress.
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.
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.
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":"CQv87WiCDgM2wE6yRW1DxBl+lQV5n0rzDurjEsJRccxu5/J0R3Ap1+oHoRmIgT3J56VrTHBG\nLm0EJBRn/7iEiT4Rg0FvbeJpqL6t9EvCJuT+fh8eygyxryuDbsurZlKR19LySG8q2NWDLLmm\nIuQqRz2arhmWK/r0+OOco0Cx8/kyYJxfO6+q2UMPkX51aiQW0OUpvYRhVeuikApnl9bSQgAB\ntxnTZ53in1VEJ/py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