Márcio Mocellin
Márcio Mocellin

Reputation: 281

How to save the password in script R in package ‘encryptr’?

I do that:

library(encryptr)
genkeys()

And I created the password: 0)]30l^8

password<-"0)]30l^8"
data(gp)
write.csv(gp, "gp.csv")
encrypt_file("gp.csv")

My problem is: How do I automatically enter the password on the decrypt_file("gp.csv.encryptr.bin", file_name = "gp2.csv")

I need this to decrypt many files in a short time.

Upvotes: 1

Views: 387

Answers (1)

Ewen
Ewen

Reputation: 1391

Many thanks for the question. Saving a password in a script is not recommended as that defeats the purpose of encrypting a file in most circumstances. You can work around this intentional feature although it is not recommended.

password<-"0)]30l^8"
.crypt = readRDS("gp.csv.encryptr.bin") # in file
zz = file("gp2.csv", "wb") # out file
openssl::decrypt_envelope(.crypt$data, .crypt$iv, .crypt$session, key = "id_rsa", password = password) %>%
  writeBin(zz)
close(zz)

Upvotes: 1

Related Questions