Easily encrypt and decrypt authentication tokens

tokencodr provides functions to easily encrypt authentication files for both interactive and non-interactive usage using the sodium package. It was inspired by gargle, and much of the code is directly adapted from the secret_* family of functions used by gargle internally. The methods employed follow this vignette on securely managing tokens.

DISCLAIMER: I am not a security expert. The methods described in this package could potentially allow certain parties to access your authorization token(s) and, subsequently, your data. Use at your own risk.


You can install and load the development version of tokencodr from GitHub as follows:

# Install the development version from GitHub
if (!require("remotes")) install.packages("remotes")

# Load package

Getting Started

tokencodr has three functions:

Function Description Example Use
create_env_pw() This function accepts a ‘service’ argument, which would typically be a one-word description for the platform whose token you are attempting to encrypt. create_env_pw(service = "BOXREXAMPLE")
encrypt_token() Accepts the service specified in create_env_pw(), an input file, and the destination directory for where the encrypted file should be saved. encrypt_token(service = "BOXREXAMPLE", input = "~/private/local/path/to/my/jwt/file.json", destination = "~/Desktop/")
decrypt_token() Accepts the service name, path to encrypted token file, and a logical ‘complete’, indicating whether the file should be returned as raw bytes or as a character string with the decoded (original) contents. decrypt_token(service = "BOXREXAMPLE", path = "~/Desktop/.secret/BOXREXAMPLE", complete = TRUE)

Further Reading

For a more in-depth explanation of tokencodr, please see the vignette.


If you want to see a feature, or report a bug, please file an issue or open a pull-request! As this package is just getting off the ground, we welcome all feedback and contributions. See our contribution guidelines for more details on getting involved!

Code of Conduct

Please note that the tokencodr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.