Description Usage Arguments Value See Also Examples
Read / Write crypted table from / to a SQLite database
1 2 3 | write_db_encrypt(conn, value, name = "credentials", passphrase = NULL)
read_db_decrypt(conn, name = "credentials", passphrase = NULL)
|
conn |
A DBIConnection object, as returned by |
value |
A |
name |
A character string specifying the unquoted DBMS table name. |
passphrase |
A secret passphrase to crypt the table inside the database |
a data.frame
for read_db_decrypt
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | # connect to database
conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:")
# write to database
write_db_encrypt(conn, value = head(iris), name = "iris", passphrase = "supersecret")
# read
read_db_decrypt(conn = conn, name = "iris", passphrase = "supersecret")
# with wrong passphrase
## Not run:
read_db_decrypt(conn = conn, name = "iris", passphrase = "forgotten")
## End(Not run)
# with DBI method you'll get a crypted blob
DBI::dbReadTable(conn = conn, name = "iris")
# add some users to database
## Not run:
conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = "path/to/database.sqlite")
# update "credentials" table
current_user <- read_db_decrypt(
conn,
name = "credentials",
passphrase = key_get("R-shinymanager-key", "obiwankenobi")
)
add_user <- data.frame(user = "new", password = "pwdToChange",
start = NA, expire = NA, admin = TRUE)
new_users <- rbind.data.frame(current_user, add_user)
write_db_encrypt(
conn,
value = new_users,
name = "credentials",
key_get("R-shinymanager-key", "obiwankenobi")
)
# update "pwd_mngt" table
pwd_mngt <- read_db_decrypt(
conn,
name = "pwd_mngt",
passphrase = key_get("R-shinymanager-key", "obiwankenobi")
)
pwd_mngt <- rbind.data.frame(
pwd_mngt,
data.frame(user = "new", must_change = T, have_changed = F, date_change = "")
)
write_db_encrypt(
conn,
value = pwd_mngt,
name = "pwd_mngt",
passphrase = key_get("R-shinymanager-key", "obiwankenobi")
)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.