Methods in this class can help admin to encrypt files been output from sps.
For now it is only used to encypt and decrypt snapshots.
This class requires the SPS database. This class inherits all functions from
the spsDb class, so there is no need to initiate the spsDb
container.
This class is required to run a SPS app. This class needs to be initialized global level. This has already been written in global.R for you.
systemPipeShiny::spsDb
-> spsEncryption
new()
initialize a new class container
spsEncryption$new()
keyChange()
Change encryption key of a SPS project
spsEncryption$keyChange(confirm = FALSE, db_name = "config/sps.db")
confirm,
bool, confirm that you understand the consequence
db_name
database path
keyGet()
Get encryption key from db of a SPS project
spsEncryption$keyGet(db_name = "config/sps.db")
db_name
database path
encrypt()
Encrypt raw data or a file with key from a SPS project
spsEncryption$encrypt( data, out_path = NULL, overwrite = FALSE, db_name = "config/sps.db" )
data
raw vector or a file path
out_path
if provided, encrypted data will be write to a file
overwrite
if out_path
file exists, overwrite?
db_name
database path
decrypt()
Decrypt raw data or a file with key from a SPS project
spsEncryption$decrypt( data, out_path = NULL, overwrite = FALSE, db_name = "config/sps.db" )
data
raw vector or a file path
out_path
if provided, encrypted data will be write to a file
overwrite
if out_path
file exists, overwrite?
db_name
database path
clone()
The objects of this class are cloneable with this method.
spsEncryption$clone(deep = FALSE)
deep
Whether to make a deep clone.
dir.create("config", showWarnings = FALSE) spsOption('verbose', TRUE) my_ecpt <- spsEncryption$new()#>#>#>#>my_ecpt$createDb()#>#>#>#>#>#>#> [SPS-DANGER] 2021-09-18 02:42:29 Done, Db created at 'config/sps.db'. DO NOT share this file with others or upload to open access domains. #> [SPS-INFO] 2021-09-18 02:42:29 Key md5 a0016bdb8cb61d7875623c74cae30754# Read carefully before change the key my_ecpt$keyChange()#> [SPS-DANGER] 2021-09-18 02:42:29 #> change this key will result all accounts' password failed to #> authenticate. You have to regenerate all password for all #> accounts. All encrypted file using the old key will fail to #> decrypt. There is NO way to RECOVER the old key, password #> and files. If you wish to continue, recall this function #> with `confirm = TRUE`.# confirm my_ecpt$keyChange(confirm = TRUE)#>#>#> [SPS-INFO] 2021-09-18 02:42:29 md5 055dccd79c2293314d91965fd1a21718# imagine a file has one line "test" writeLines(text = "test", con = "test.txt") # encrypt the file my_ecpt$encrypt("test.txt", "test.bin", overwrite = TRUE)#>#>#>#>#># decrypt the file my_ecpt$decrypt("test.bin", "test_decpt.txt", overwrite = TRUE)#>#>#>#>#>#>#> [1] "test"