R/development/review/data-raw/encrypt_config.R

Defines functions set_new_encrypted

library(yaml)
library(sodium)

##
## Set & save password to encrypt config list and hashed pwd check
##
set_new_encrypted <- function(pwd = NULL, run_build=TRUE){
  if(is.null(pwd))
    pwd <- rstudioapi::askForPassword("Save new password:")

  if(!is.null(pwd)){
    ##
    ## save password just receieved
    ##
    key <- sodium::sha256(charToRaw(pwd))
    saveRDS(sodium::password_store(pwd), file = "inst/temp/hash_pwd")

    ## read and store config yml file as encrypted binary
    ##
    hpds <- readLines("private/hdps_yml")
    hpds_list <- yaml::yaml.load(paste0(hpds, collapse = "\n"))

    config_ciph <- sodium::data_encrypt(serialize(hpds_list, NULL), key)
    saveRDS(config_ciph, "inst/temp/config_ciph")

    if(run_build) devtools::document()
    return(TRUE)
  }
  return(FALSE)
}



set_new_encrypted("Newyork1")
bfatemi/ninjar documentation built on Sept. 8, 2019, 7:37 p.m.