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":"2Wmp3HZe643t26kl7Vrw+J2r/bq8U3TBkBSJKXyONJKvNsQ3mtVgwQk6l28CNMDiI7Qz3k34\nLstxjkdZxWBWNCZxLhqXPTMLoAgIRqt6st1ZlfappZIRAuAHkiAzwfc05ZB6X1pkcWubYpdi\nx1TIi8suKJjajHO9XPzvkv1+yAgb0h1mQr/oJmwcGoI/5jdYiiUCQdALhtk7+IOVMg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