【问题标题】:How do i store sensitive data (such as Database passwords) in an Oracle Database如何在 Oracle 数据库中存储敏感数据(例如数据库密码)
【发布时间】:2019-09-07 15:31:58
【问题描述】:

基本上,我正在构建一个使用 Oracle 数据库的 WebApp (ASP.NET MVC5)。应用程序连接到多个 oracle 数据库,管理员应该能够动态地将新的数据库连接添加到 webapp。

我们现在的做法是,当管理员通过管理面板添加新数据库时,数据库连接信息存储在我们自己的 Oracle 数据库中(包括数据库的用户名和密码)。这些密码当前以明文形式存储。

webapp 所要做的就是从我们自己的数据库中检索数据库凭据,将它们格式化为连接字符串并连接到数据库。

问题是,如果我们对密码进行哈希处理,它们将无法在连接字符串中工作,这也不会增加任何安全性。这些密码的所有加密都应该在数据库端进行。

我发现了 TDE(透明数据加密),但我相信这仅在 Oracle 数据库的企业版中可用,我无权访问它。有没有其他方法可以安全地存储数据库密码?我错过了什么吗?

【问题讨论】:

  • 好问题。如果您想推出自己的 2 路加密,以便您可以加密新密码并将其加密存储,然后在连接到数据库时将其解密以供使用。我建议,因为帐户/密码将由 webapp 使用,所以可能有双重加密,其中纯密码只能通过组合 PLSQL 解密和 WebApp 解密来解决,例如clearTextPwd = WebAppDecrypt(PLSQLDecyrpt(db_stored_enc_pwd))。有效 2 键。如果这让您感到害怕,请使用 Kerberos 之类的工具查看 Oracle 中的 EXTERNALLY IDENTIFIED 用户。

标签: asp.net oracle security encryption


【解决方案1】:

您可以简单地加密密码并将其存储在数据库中。当用户更改密码或首次注册时,只需对其进行加密。在检查验证时,加密文本框并检查两个字符串是否匹配。
当您需要知道密码时,请解密它们。
加密的示例代码如下所示

        // Encrypt the text
        public static string EncryptText(string strText)
        {
            return Encrypt(strText, "a#94tOc*"); // use any string to encrypt other than a#94tOc*
        }

        //The function used to encrypt the text
        private static string Encrypt(string strText, string strEncrKey)
        {
            byte[] byKey = { };
            byte[] IV = { 0X12, 0X34, 0X56, 0X78, 0X90, 0XAB, 0XCD, 0XEF };
            byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8));
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            byte[] inputByteArray = System.Text.Encoding.UTF8.GetBytes(strText);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            return Convert.ToBase64String(ms.ToArray());
        }

同样用于解密,使用:

        //Decrypt the text 
        public static string DecryptText(string strText)
        {
            return Decrypt(strText, "a#94tOc*"); // use same as encryption string
        }
        //The function used to decrypt the text
        private static string Decrypt(string strText, string sDecrKey)
        {
            byte[] byKey = { };
            byte[] IV = { 0X12, 0X34, 0X56, 0X78, 0X90, 0XAB, 0XCD, 0XEF };
            byte[] inputByteArray = new byte[strText.Length + 1];
            byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0, 8));
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            inputByteArray = Convert.FromBase64String(strText.Replace(' ', '+'));
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            System.Text.Encoding encoding = System.Text.Encoding.UTF8;
            return encoding.GetString(ms.ToArray());
        }

所以基本上只需调用EncryptText(password) 进行加密和DecryptText(encrypted_password) 进行解密。

【讨论】:

  • 但是我会在哪里存储加密密钥?
  • 您可以将其保存在 C# 文件中,也可以将其存储在数据库中。
  • 但是我如何将加密密钥安全地存储在数据库中?
  • 其实你可以把它保存在 C# 文件中,因为你知道你的加密密钥并且密码会被加密
猜你喜欢
  • 2011-01-19
  • 1970-01-01
  • 2012-03-19
  • 2017-11-26
  • 1970-01-01
  • 2012-03-28
  • 1970-01-01
  • 1970-01-01
  • 2021-04-10
相关资源
最近更新 更多