在 R 中加密密码 - 使用 RODBC 连接到 Oracle DB
问题描述
我使用以下代码连接Oracle数据库:
I use the following code to connect Oracle database:
但是,我不能在公共场合使用明文密码.我想加密密码.
However, I cannot use a cleartext password in public. I want to encrypt the password.
我看到一个 pki
和 digest
库要使用,这是一种方法吗?
I see a pki
and digest
library to use, is this a way to do it?
更新
我试过下面的代码:
Update
I tried below code :
加密是这样完成的吗?我应该使用这样的东西吗:
Is this how the encryption is done? Should I use something like this:
推荐答案
以下功能现在可以在我的 R 包中使用 keyringr.keyringr 包也有类似的功能来访问 Gnome Keyring 和 macOS Keychain.
The below functionality is now available in my R package keyringr. The keyringr package also has similar functions to access the Gnome Keyring and macOS Keychain.
---
如果您使用的是 Windows,则可以使用 PowerShell 来执行此操作.请参阅下面的博客文章.
If you are using Windows you can use PowerShell to do this. See my blog post below.
http://www.gilfillan.space/2016/04/21/Using-PowerShell-and-DPAPI-to-securely-mask-passwords-in-R-scripts/
基本上...
确保您已启用 PowerShell 执行.
将以下文本保存到名为 EncryptPassword.ps1 的文件中:
Save the following text into a file called EncryptPassword.ps1:
执行上面的脚本(右键单击 > 使用 PowerShell 运行),为密码提供一个有意义的名称,然后输入密码.您现在可以通过检查 %USERPROFILE%/DPAPI/passwords/[PC NAME]/[PASSWORD IDENTIFIER.txt] 中的文件来验证密码是否已加密
Execute the script above (right click > Run with PowerShell), provide a meaningful name for the password, and type in the password. You can now verify that the password has been encrypted by checking the file in %USERPROFILE%/DPAPI/passwords/[PC NAME]/[PASSWORD IDENTIFIER.txt]
现在在 R 中运行以下代码(我将此函数保存在一个 R 脚本中,我 source 在每个脚本的开头.
Now run the following code from within R (I have this function saved in an R script that I source at the start of each script.
现在,当您需要在 R 中提供密码时,您可以运行以下命令,而不是硬编码/提示输入密码:
Now when you need to supply a password in R, you can run the following command instead of hardcoding / prompting for the password:
例如,而不是运行 ROracle 命令:
For example, instead of running the ROracle command:
您可以改为运行它(我在第 3 步中提供的标识符是MYUSER_MYDB":
You can run this instead (the identifier I supplied in Step 3 is "MYUSER_MYDB":
这篇关于在 R 中加密密码 - 使用 RODBC 连接到 Oracle DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!