Created
March 8, 2019 23:00
-
-
Save ras44/cedbe5ba0230787a3a57a8db955494d3 to your computer and use it in GitHub Desktop.
Securing Credentials using Keyrings in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(keyring) | |
# Set variables to be used in keyring. | |
kr_name <- "my_keyring" | |
kr_service <- "my_database" | |
kr_username <- "my_username" | |
# Create a keyring and add an entry using the variables above | |
kb <- keyring::backend_file$new() | |
# Prompt for the keyring password, used to unlock keyring | |
kb$keyring_create(kr_name) | |
# Prompt for the password to be stored in the keyring | |
kb$set(kr_service, username=kr_username, keyring=kr_name) | |
# Lock the keyring | |
kb$keyring_lock(kr_name) | |
# The encrypted keyring file is now stored at ~/.config/r-keyring/ and can be | |
# accessed by any R program that provides the keyring password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment