-
Help
DescriptionHi, first off thank you for the great targets package. The issue I run into is that loading an encryption key is always considered outdated, so loading or saving any data dependent on that key is also considered outdated. I've tried to google and look through forums to find a workaround, but no luck! Below is a reproducible example (based on a previous similar question from a few years back (#448)
After running Any thoughts on how to load an encryption key in a way that it remains updated unless the value in .Renviron changes? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
How about the example below? Note the use of sha512 to detect changes to the data key. I would have used library(targets)
library(tarchetypes)
library(tidyverse)
library(here)
library(cyphr)
data_key_hash <- digest::digest(Sys.getenv("DATA_KEY"), algo = "sha512")
make_data <- function(){
x <- as_tibble(airquality)
return(x)
}
make_summary <- function(dataset) {
dataset %>%
janitor::clean_names() %>%
group_by(month) %>%
summarize()
}
setup <- list(
tar_target(
cyphr_key, {
data_key_hash
cyphr::key_sodium(sodium::hex2bin(Sys.getenv("DATA_KEY")))
}
)
)
pipeline <- list(
tar_target(data, make_data()),
tar_target(summary, make_summary(data))
) %>%
tar_hook_outer(hook = encrypt_object(.x, key = cyphr_key)) %>%
tar_hook_inner(hook = decrypt_object(.x, key = cyphr_key))
list(setup, pipeline) |
Beta Was this translation helpful? Give feedback.
-
Hi, thank you for the quick response! It looks like with the code as is, if you modify pipeline you get the following error;
This should load the key properly. Thank you for your help! |
Beta Was this translation helpful? Give feedback.
Hi, thank you for the quick response!
It looks like with the code as is, if you modify pipeline you get the following error;
Failed to decrypt key as session key has changed
. It looks like cyphr load sessions specific keys by design. To get around this I changed how to key is loaded in the tar_hooks statements, as follows: