具有完全AES加密性能问题的数据库

时间:2019-03-27 16:21:01

标签: c# encryption aes

我的客户希望使用AES加密所有内容,以保护客户/发票信息!我使用Mysql数据库(Hostgator上的主机)制作了.net应用程序。基本上有效

我的解决方案是,在.net应用程序启动时,我们加载所有数据(约12,000行)解密并添加到缓存列表中。想法是从此列表中我们在ViewForm上进行处理,并在更新数据时加密数据并更新回Mysql数据库。

对于大约5到10行,它可以顺利进行处理,搜索和更新到服务器,但是在将12K数据导入数据库后,我们遇到了问题,启动和加载初始文件花了5到7个小时我必须找到解决方案。

解密代码:

Using aesAlg As New AesCryptoServiceProvider()
        aesAlg.Key = Key
        aesAlg.IV = IV

        ' Create a decryptor to perform the stream transform.
        Dim decryptor As ICryptoTransform = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV)

        Using msDecrypt As New MemoryStream()
            Using csDecrypt As New CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Write)
                csDecrypt.Write(cipherText, 0, cipherText.Length)
                csDecrypt.FlushFinalBlock()
                'Using srDecrypt As New StreamReader(csDecrypt)
                '    csDecrypt.FlushFinalBlock()
                plaintext = msDecrypt.ToArray
                '    Return plaintext
                'End Using
            End Using
        End Using
    End Using

用于加密的代码:

Using aesAlg As New AesCryptoServiceProvider()
        aesAlg.Key = Key
        aesAlg.IV = IV

        ' Create an encryptor to perform the stream transform.
        Dim encryptor As ICryptoTransform = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV)

        ' Create the streams used for encryption.
        Using msEncrypt As New MemoryStream()
            Using csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)
                csEncrypt.Write(plainText, 0, plainText.Length)
                csEncrypt.FlushFinalBlock()
                encrypted = msEncrypt.ToArray()
            End Using
        End Using
    End Using

    ' Return the encrypted bytes from the memory stream.
    Return encrypted

我曾经在启动时将所有内容加载到缓存(〜40个属性x 12K行)

list = (From p In Entities.Products.ToList() 
Select New Product With {.ProductID = p.ProductID,
  .PROPERTY = p.PROPERTY,
  .PROPERTY = Decrypt(p.PROPERTY),
  .PROPERTY = Decrypt(p.PROPERTY),
  .PROPERTY = Decrypt(p.PROPERTY),
  .PROPERTY = Decrypt(p.PROPERTY),
  .PROPERTY = Decrypt(p.PROPERTY),
  .PROPERTY = Decrypt(p.PROPERTY),
  .PROPERTY = Decrypt(p.PROPERTY),}

)。ToList()

有人对此问题有经验,请给我提供解决方案的建议。

0 个答案:

没有答案