rodbc 连接oracle,在R中加密密码 – 使用RODBC连接到Oracle DB
編輯:以下功能現在可以在我的R包
keyringr中使用.Keyringr包也具有類似的功能來訪問Gnome Keyring和macOS Keychain.
—
如果您使用的是Windows,則可以使用PowerShell執行此操作.請參閱下面的博文.
從本質上講…
>確保你有enabled PowerShell execution.
>將以下文本保存到名為EncryptPassword.ps1的文件中:
# Create directory user profile if it doesn't already exist.
$passwordDir = "$($env:USERPROFILE)\DPAPI\passwords\$($env:computername)"
New-Item -ItemType Directory -Force -Path $passwordDir
# Prompt for password to encrypt
$account = Read-Host "Please enter a label for the text to encrypt. This will be how you refer to the password in R. eg. MYDB_MYUSER
$SecurePassword = Read-Host -AsSecureString "Enter password" | convertfrom-securestring | out-file "$($passwordDir)\$($account).txt"
# Check output and press any key to exit
Write-Host "Press any key to continue..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
>執行上面的腳本(右鍵單擊>使用PowerShell運行),為密碼提供有意義的名稱,然后輸入密碼.您現在可以通過檢查%USERPROFILE%/ DPAPI / passwords / [PC NAME] / [PASSWORD IDENTIFIER.txt]中的文件來驗證密碼是否已加密
>現在從R中運行以下代碼(我將此函數保存在每個腳本開頭的I source的R腳本中.
getEncryptedPassword
# if path not supplied, use %USER_PROFILE%\DPAPI\passwords\computername\credential_label.txt as default
if (missing(credential_path)) {
credential_path
}
# construct command
command
# execute powershell and return command
return(system(command, intern=TRUE))
}
>現在,當您需要在R中提供密碼時,可以運行以下命令,而不是硬編碼/提示輸入密碼:
getEncryptedPassword("[PASSWORD IDENTIFIER]")
例如,而不是運行ROracle命令:
dbConnect(driver, "MYUSER", "MY PASSWORD", dbname="MYDB")
你可以改為運行它(我在步驟3中提供的標識符是“MYUSER_MYDB”:
dbConnect(driver, "MYUSER", getEncryptedPassword("MYUSER_MYDB"), dbname="MYDB")
>您可以根據需要重復步驟3以獲取盡可能多的密碼,并在步驟5中使用正確的標識符進行呼叫.
總結
以上是生活随笔為你收集整理的rodbc 连接oracle,在R中加密密码 – 使用RODBC连接到Oracle DB的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MATLAB1770太阳黑子,基于MAT
- 下一篇: oracle locked time,O