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.

Super class

systemPipeShiny::spsDb -> spsEncryption

Methods

Public methods

Inherited methods

Method new()

initialize a new class container

Usage

spsEncryption$new()


Method keyChange()

Change encryption key of a SPS project

Usage

spsEncryption$keyChange(confirm = FALSE, db_name = "config/sps.db")

Arguments

confirm,

bool, confirm that you understand the consequence

db_name

database path


Method keyGet()

Get encryption key from db of a SPS project

Usage

spsEncryption$keyGet(db_name = "config/sps.db")

Arguments

db_name

database path


Method encrypt()

Encrypt raw data or a file with key from a SPS project

Usage

spsEncryption$encrypt(
  data,
  out_path = NULL,
  overwrite = FALSE,
  db_name = "config/sps.db"
)

Arguments

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


Method decrypt()

Decrypt raw data or a file with key from a SPS project

Usage

spsEncryption$decrypt(
  data,
  out_path = NULL,
  overwrite = FALSE,
  db_name = "config/sps.db"
)

Arguments

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


Method clone()

The objects of this class are cloneable with this method.

Usage

spsEncryption$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

dir.create("config", showWarnings = FALSE) spsOption('verbose', TRUE) my_ecpt <- spsEncryption$new()
#> [SPS-INFO] 2021-09-18 02:42:28 Created SPS encryption method container
#> [SPS-INFO] 2021-09-18 02:42:28 This container inherits all functions from spsDb class
#> [SPS-INFO] 2021-09-18 02:42:28 Db connected
#> [SPS-INFO] 2021-09-18 02:42:28 Default SPS-db found and is working
my_ecpt$createDb()
#> [SPS-INFO] 2021-09-18 02:42:28 Db connected
#> [SPS-INFO] 2021-09-18 02:42:28 Creating SPS db...
#> [SPS-INFO] 2021-09-18 02:42:28 Db write the meta table
#> [SPS-INFO] 2021-09-18 02:42:29 Db write the raw table
#> [SPS-INFO] 2021-09-18 02:42:29 Key generated and stored in db
#> [SPS-INFO] 2021-09-18 02:42:29 Db create admin account
#> [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 Db connected
#> [SPS-INFO] 2021-09-18 02:42:29 You new key has been generated and saved in db
#> [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)
#> [SPS-INFO] 2021-09-18 02:42:29 Db connected
#> [SPS-INFO] 2021-09-18 02:42:29 Query sent
#> [SPS-INFO] 2021-09-18 02:42:29 OpenSSL key found md5055dccd79c2293314d91965fd1a21718
#> [SPS-INFO] 2021-09-18 02:42:29 Data encrypted
#> [SPS-INFO] 2021-09-18 02:42:29 File write to /home/runner/work/systemPipeShiny/systemPipeShiny/docs/reference/test.bin
# decrypt the file my_ecpt$decrypt("test.bin", "test_decpt.txt", overwrite = TRUE)
#> [SPS-INFO] 2021-09-18 02:42:29 File read into memory
#> [SPS-INFO] 2021-09-18 02:42:29 Db connected
#> [SPS-INFO] 2021-09-18 02:42:29 Query sent
#> [SPS-INFO] 2021-09-18 02:42:29 OpenSSL key found md5055dccd79c2293314d91965fd1a21718
#> [SPS-INFO] 2021-09-18 02:42:29 Data decrypted
#> [SPS-INFO] 2021-09-18 02:42:29 File write to /home/runner/work/systemPipeShiny/systemPipeShiny/docs/reference/test_decpt.txt
# check the decrypted file content readLines('test_decpt.txt')
#> [1] "test"