2017-07-27 32 views
3

让我对加密技术知之甚少,我试图找到在某些vb.net winform应用程序中散列用户密码的最佳方法;然后将其存储在在线mysql分贝。 我发现了很多有关该主题的帖子,但无法弄清楚哪一个是最好的方法。什么是最新的密码哈希算法/数据加密为MySQL?

我到达this MSDN post但仍不能确定我是否可以使用它。

我不能在哪里输入一些随机密钥,它是由函数自动生成的。

所以我的问题是,这是一个密码哈希的固体功能? 任何替代品?

谢谢

代码:

 

Imports System 
Imports System.IO 
Imports System.Security.Cryptography 



Class AesExample 

    Public Shared Sub Main() 
     Try 

      Dim original As String = "Here is some data to encrypt!" 

      ' Create a new instance of the Aes 
      ' class. This generates a new key and initialization 
      ' vector (IV). 
      Using myAes As Aes = Aes.Create() 

       ' Encrypt the string to an array of bytes. 
       Dim encrypted As Byte() = EncryptStringToBytes_Aes(original, myAes.Key, myAes.IV) 

       ' Decrypt the bytes to a string. 
       Dim roundtrip As String = DecryptStringFromBytes_Aes(encrypted, myAes.Key, myAes.IV) 

       'Display the original data and the decrypted data. 
       Console.WriteLine("Original: {0}", original) 
       Console.WriteLine("Round Trip: {0}", roundtrip) 
      End Using 
     Catch e As Exception 
      Console.WriteLine("Error: {0}", e.Message) 
     End Try 

    End Sub 'Main 

    Shared Function EncryptStringToBytes_Aes(ByVal plainText As String, ByVal Key() As Byte, ByVal IV() As Byte) As Byte() 
     ' Check arguments. 
     If plainText Is Nothing OrElse plainText.Length

回答

2

不加密的密码,当攻击者得到的DB,他也将获得加密密钥。仅仅使用散列函数是不够的,只是添加盐对提高安全性没有多大作用。使用随机盐在HMAC上迭代大约100毫秒的持续时间,并用散列表保存盐。使用功能,如ehash,PBKDF2,Bcrypt,passlib.hash或类似的功能。关键是要让攻击者花费大量时间通过强力查找密码。

NIST当前推荐PBKDF2作为密码验证程序。

参见:

+0

太谢谢你了@zap h,如果你可以发布一个链接到vb.net的实现,那会很棒。谢谢 – wpcoder

+1

.NET [Rfc2898DeriveBytes](https://msdn.microsoft.com/en-us/library/system.security.cryptography.rfc2898derivebytes(v = vs.110).aspx),是PBKDF2它只是MS喜欢添加混乱。 – zaph