R/decrypt_functions.R

# function for encrypting a password
pwdEncrypt <- function(password, key){
  require(PKI)
  pwdRaw <- charToRaw(password)
  pwdEncrypted <-PKI.encrypt(pwdRaw, key)
  return(pwdEncrypted)
}

# function for decrypting a password
pwdDecrypt <- function(encrypted_password, key){
  require(PKI)
  pwdRaw <- PKI.decrypt(encrypted_password, key)
  pwd <- rawToChar(pwdRaw)
  return(pwd)
}

# function to save encrypted password

pwdSaveRDS <- function(encrypted_password, file, location){
  require(PKI)

  if(missing(location)){
    location <- getwd()
    location_file <- paste0(location, "/", file)
    saveRDS(object = encrypted_password, file = location_file)
    return(print(paste0("Password saved as: '", location_file, "' ")))
  } else {
    location_file <- paste0(location, "/", file)
    saveRDS(object = encrypted_password, file = location_file)
    return(print(paste0("Password saved as: '", location_file, "' ")))
  }
}

# function to load encrypted password

pwdLoadRDS <- function(location_file){
  require(PKI)
  pwd <- readRDS(location_file)
  return(pwd)
}
ArieTwigt/passwordEncryptR documentation built on May 30, 2019, 7:58 p.m.