rodbc 连接oracle,在R中加密密码 – 使用RODBC连接到Oracle DB
編輯:以下功能現(xiàn)在可以在我的R包
keyringr中使用.Keyringr包也具有類(lèi)似的功能來(lái)訪問(wèn)Gnome Keyring和macOS Keychain.
—
如果您使用的是Windows,則可以使用PowerShell執(zhí)行此操作.請(qǐng)參閱下面的博文.
從本質(zhì)上講…
>確保你有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")
>執(zhí)行上面的腳本(右鍵單擊>使用PowerShell運(yùn)行),為密碼提供有意義的名稱(chēng),然后輸入密碼.您現(xiàn)在可以通過(guò)檢查%USERPROFILE%/ DPAPI / passwords / [PC NAME] / [PASSWORD IDENTIFIER.txt]中的文件來(lái)驗(yàn)證密碼是否已加密
>現(xiàn)在從R中運(yùn)行以下代碼(我將此函數(shù)保存在每個(gè)腳本開(kāi)頭的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))
}
>現(xiàn)在,當(dāng)您需要在R中提供密碼時(shí),可以運(yùn)行以下命令,而不是硬編碼/提示輸入密碼:
getEncryptedPassword("[PASSWORD IDENTIFIER]")
例如,而不是運(yùn)行ROracle命令:
dbConnect(driver, "MYUSER", "MY PASSWORD", dbname="MYDB")
你可以改為運(yùn)行它(我在步驟3中提供的標(biāo)識(shí)符是“MYUSER_MYDB”:
dbConnect(driver, "MYUSER", getEncryptedPassword("MYUSER_MYDB"), dbname="MYDB")
>您可以根據(jù)需要重復(fù)步驟3以獲取盡可能多的密碼,并在步驟5中使用正確的標(biāo)識(shí)符進(jìn)行呼叫.
總結(jié)
以上是生活随笔為你收集整理的rodbc 连接oracle,在R中加密密码 – 使用RODBC连接到Oracle DB的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: MATLAB1770太阳黑子,基于MAT
- 下一篇: oracle locked time,O