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":"b87tZJmGCdCAPHoqYnltz0n49FkCR2P3XzZ53/mVQ6WTi9SpFe/4V97IY51cWuUnhbebynQZ\nxBAlZ84AJv8/I5cXAvn19a9V0zOpLCYKBpiZ08v6C8KLJKcqusWdY8JULPz8ryD+TGiTLnJp\nJmpxILpuL3tjaXKl4h7SKIvdPTmkDjPFa7oTthuSQ1sXv2PvNTeAwTX90Tfs/NcGa6/YKD9y\ncDdvyRD7cbRmq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