misc/sodium_playground.R

library(sodium)

# Generate keypair, share pub with LORIS
key <- keygen()
pub <- pubkey(key)

# Encrypt id with pubkey in LORIS
id <- "17"

id_encrypted <- serialize(id,  NULL) |> 
  simple_encrypt(pub) |> 
  bin2hex()

nchar(id_encrypted)  # this is a bit long but should be okay for an URL

# Generate URL in LORIS
(url <- paste0("https://ucsd-cmig.shinyapps.io/hbcdtlfb-dev/?encryptedid=", id_encrypted))

# Decrypt id with private key in the app
id_decrypted <- id_encrypted |> 
  hex2bin() |> 
  simple_decrypt(key) |> 
  unserialize()
ucsd-dsm/hbcd-tlfb documentation built on July 10, 2022, 5:46 p.m.