Vb.net 如何解密MD5哈希
我已使用以下函数加密我的密码:Vb.net 如何解密MD5哈希,vb.net,Vb.net,我已使用以下函数加密我的密码: HashPasswordForStoringInConfigFile(Password, "MD5") 现在我想再次解密密码 注意我在网格视图中显示加密的密码,我想在特定行进入编辑模式时对其进行解密。您可以使用类似的加密和解密功能对文本进行加密和解密,您还可以根据需要显示解密文本 下面是函数 Public Function Encrypt(ByVal plainText As String) As String Dim passPhrase As St
HashPasswordForStoringInConfigFile(Password, "MD5")
现在我想再次解密密码
注意我在网格视图中显示加密的密码,我想在特定行进入编辑模式时对其进行解密。您可以使用类似的加密和解密功能对文本进行加密和解密,您还可以根据需要显示解密文本 下面是函数
Public Function Encrypt(ByVal plainText As String) As String
Dim passPhrase As String = "yourPassPhrase"
Dim saltValue As String = "mySaltValue"
Dim hashAlgorithm As String = "MD5"
Dim passwordIterations As Integer = 2
Dim initVector As String = "@1B2c3D4e5F6g7H8"
Dim keySize As Integer = 256
Dim initVectorBytes As Byte() = Encoding.ASCII.GetBytes(initVector)
Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)
Dim plainTextBytes As Byte() = Encoding.UTF8.GetBytes(plainText)
Dim password As New PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations)
Dim keyBytes As Byte() = password.GetBytes(keySize \ 8)
Dim symmetricKey As New RijndaelManaged()
symmetricKey.Mode = CipherMode.CBC
Dim encryptor As ICryptoTransform = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes)
Dim memoryStream As New MemoryStream()
Dim cryptoStream As New CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length)
cryptoStream.FlushFinalBlock()
Dim cipherTextBytes As Byte() = memoryStream.ToArray()
memoryStream.Close()
cryptoStream.Close()
Dim cipherText As String = Convert.ToBase64String(cipherTextBytes)
Return cipherText
End Function
对于解密,请使用此
Public Function Decrypt(ByVal cipherText As String) As String
Dim passPhrase As String = "yourPassPhrase"
Dim saltValue As String = "mySaltValue"
Dim hashAlgorithm As String = "MD5"
Dim passwordIterations As Integer = 2
Dim initVector As String = "@1B2c3D4e5F6g7H8"
Dim keySize As Integer = 256
' Convert strings defining encryption key characteristics into byte
' arrays. Let us assume that strings only contain ASCII codes.
' If strings include Unicode characters, use Unicode, UTF7, or UTF8
' encoding.
Dim initVectorBytes As Byte() = Encoding.ASCII.GetBytes(initVector)
Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)
' Convert our ciphertext into a byte array.
Dim cipherTextBytes As Byte() = Convert.FromBase64String(cipherText)
' First, we must create a password, from which the key will be
' derived. This password will be generated from the specified
' passphrase and salt value. The password will be created using
' the specified hash algorithm. Password creation can be done in
' several iterations.
Dim password As New PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations)
' Use the password to generate pseudo-random bytes for the encryption
' key. Specify the size of the key in bytes (instead of bits).
Dim keyBytes As Byte() = password.GetBytes(keySize \ 8)
' Create uninitialized Rijndael encryption object.
Dim symmetricKey As New RijndaelManaged()
' It is reasonable to set encryption mode to Cipher Block Chaining
' (CBC). Use default options for other symmetric key parameters.
symmetricKey.Mode = CipherMode.CBC
' Generate decryptor from the existing key bytes and initialization
' vector. Key size will be defined based on the number of the key
' bytes.
Dim decryptor As ICryptoTransform = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes)
' Define memory stream which will be used to hold encrypted data.
Dim memoryStream As New MemoryStream(cipherTextBytes)
' Define cryptographic stream (always use Read mode for encryption).
Dim cryptoStream As New CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)
' Since at this point we don't know what the size of decrypted data
' will be, allocate the buffer long enough to hold ciphertext;
' plaintext is never longer than ciphertext.
Dim plainTextBytes As Byte() = New Byte(cipherTextBytes.Length - 1) {}
' Start decrypting.
Dim decryptedByteCount As Integer = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length)
' Close both streams.
memoryStream.Close()
cryptoStream.Close()
' Convert decrypted data into a string.
' Let us assume that the original plaintext string was UTF8-encoded.
Dim plainText As String = Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount)
' Return decrypted string.
Return plainText
End Function
并调用将得到结果的函数。您可以像这样使用加密和解密函数对文本进行加密和解密,并且还可以根据需要显示解密文本 下面是函数
Public Function Encrypt(ByVal plainText As String) As String
Dim passPhrase As String = "yourPassPhrase"
Dim saltValue As String = "mySaltValue"
Dim hashAlgorithm As String = "MD5"
Dim passwordIterations As Integer = 2
Dim initVector As String = "@1B2c3D4e5F6g7H8"
Dim keySize As Integer = 256
Dim initVectorBytes As Byte() = Encoding.ASCII.GetBytes(initVector)
Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)
Dim plainTextBytes As Byte() = Encoding.UTF8.GetBytes(plainText)
Dim password As New PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations)
Dim keyBytes As Byte() = password.GetBytes(keySize \ 8)
Dim symmetricKey As New RijndaelManaged()
symmetricKey.Mode = CipherMode.CBC
Dim encryptor As ICryptoTransform = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes)
Dim memoryStream As New MemoryStream()
Dim cryptoStream As New CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length)
cryptoStream.FlushFinalBlock()
Dim cipherTextBytes As Byte() = memoryStream.ToArray()
memoryStream.Close()
cryptoStream.Close()
Dim cipherText As String = Convert.ToBase64String(cipherTextBytes)
Return cipherText
End Function
对于解密,请使用此
Public Function Decrypt(ByVal cipherText As String) As String
Dim passPhrase As String = "yourPassPhrase"
Dim saltValue As String = "mySaltValue"
Dim hashAlgorithm As String = "MD5"
Dim passwordIterations As Integer = 2
Dim initVector As String = "@1B2c3D4e5F6g7H8"
Dim keySize As Integer = 256
' Convert strings defining encryption key characteristics into byte
' arrays. Let us assume that strings only contain ASCII codes.
' If strings include Unicode characters, use Unicode, UTF7, or UTF8
' encoding.
Dim initVectorBytes As Byte() = Encoding.ASCII.GetBytes(initVector)
Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)
' Convert our ciphertext into a byte array.
Dim cipherTextBytes As Byte() = Convert.FromBase64String(cipherText)
' First, we must create a password, from which the key will be
' derived. This password will be generated from the specified
' passphrase and salt value. The password will be created using
' the specified hash algorithm. Password creation can be done in
' several iterations.
Dim password As New PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations)
' Use the password to generate pseudo-random bytes for the encryption
' key. Specify the size of the key in bytes (instead of bits).
Dim keyBytes As Byte() = password.GetBytes(keySize \ 8)
' Create uninitialized Rijndael encryption object.
Dim symmetricKey As New RijndaelManaged()
' It is reasonable to set encryption mode to Cipher Block Chaining
' (CBC). Use default options for other symmetric key parameters.
symmetricKey.Mode = CipherMode.CBC
' Generate decryptor from the existing key bytes and initialization
' vector. Key size will be defined based on the number of the key
' bytes.
Dim decryptor As ICryptoTransform = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes)
' Define memory stream which will be used to hold encrypted data.
Dim memoryStream As New MemoryStream(cipherTextBytes)
' Define cryptographic stream (always use Read mode for encryption).
Dim cryptoStream As New CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)
' Since at this point we don't know what the size of decrypted data
' will be, allocate the buffer long enough to hold ciphertext;
' plaintext is never longer than ciphertext.
Dim plainTextBytes As Byte() = New Byte(cipherTextBytes.Length - 1) {}
' Start decrypting.
Dim decryptedByteCount As Integer = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length)
' Close both streams.
memoryStream.Close()
cryptoStream.Close()
' Convert decrypted data into a string.
' Let us assume that the original plaintext string was UTF8-encoded.
Dim plainText As String = Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount)
' Return decrypted string.
Return plainText
End Function
然后调用函数,您将得到结果。简单的答案是“您不能”
散列的思想是从真实密码生成一个“安全”代码,该代码可以明文存储;在数据库(或文本文件)中,其他用户可能会以某种方式看到它
当有人尝试登录时,您的系统将从新登录中计算另一个哈希值,然后与现有数据库中的现有哈希值进行比较,如果哈希值匹配,则您知道这是正确的密码,然后您可以允许他们登录,否则,就不是相同的密码/登录失败
无法反转哈希的原因是,通过执行以下步骤计算哈希:
1) 将密码放入某些算法中,以:
2) 生成一个非常大的字符串,然后:
3) 切掉那根绳子,然后:
4) 把它的一部分作为你的“杂烩”
因此,你看,即使你是解码方面的超人,能够找出算法,知道散列码,并设法将其还原为原始形式,那么你仍然会丢失部分密码,因此不成功
这就是为什么散列是安全的
我希望这能解释它。简单的答案是“你不能”
散列的思想是从真实密码生成一个“安全”代码,该代码可以明文存储;在数据库(或文本文件)中,其他用户可能会以某种方式看到它
当有人尝试登录时,您的系统将从新登录中计算另一个哈希值,然后与现有数据库中的现有哈希值进行比较,如果哈希值匹配,则您知道这是正确的密码,然后您可以允许他们登录,否则,就不是相同的密码/登录失败
无法反转哈希的原因是,通过执行以下步骤计算哈希:
1) 将密码放入某些算法中,以:
2) 生成一个非常大的字符串,然后:
3) 切掉那根绳子,然后:
4) 把它的一部分作为你的“杂烩”
因此,你看,即使你是解码方面的超人,能够找出算法,知道散列码,并设法将其还原为原始形式,那么你仍然会丢失部分密码,因此不成功
这就是为什么散列是安全的
我希望这能解释这一点。目前还不可能将密码的散列放入算法中,然后以明文形式返回密码,因为散列是单向的。但人们所做的是生成散列并将其存储在一个大表中,这样当您输入一个特定的散列时,它会检查表中与散列匹配的密码,并将该密码返回给您。这样做的站点示例如下。现代密码存储系统通过使用盐析算法来应对这种情况,这样,当您在注册期间将同一密码输入密码框时,会生成不同的哈希值。由于哈希是单向的,所以现在还不可能将密码的哈希值放入算法并以明文形式返回密码。但人们所做的是生成散列并将其存储在一个大表中,这样当您输入一个特定的散列时,它会检查表中与散列匹配的密码,并将该密码返回给您。这样做的站点示例如下。现代密码存储系统通过使用一种盐析算法来应对这种情况,这样,当您在注册期间向密码框中输入相同的密码时,将生成不同的哈希。您无法解密哈希。。。而且你无论如何也不能解密密码。原因很简单:哈希将字符串映射到某个数字/id,但可能会发生冲突-不同的输入具有相同的输出-因此函数不是内射的。如果这将是一个真正的产品,考虑到安全性,请获得一些专家帮助-我已经可以告诉您,您的产品将根本不安全!(例如:在散列之前,你应该在你的密码中添加盐,MD5是一种)@shafay用于加密你的密码我会说没有用或类似的话。。。但是真的:不要自己实现加密/安全性(只有这么多人不适用此规则-我除外)-(从我上面链接的讨论中很容易找到此链接-但就这样吧)好的。。谢谢大家!您无法解密哈希。。。而且你无论如何也不能解密密码。原因很简单:哈希将字符串映射到某个数字/id,但可能会发生冲突-不同的输入具有相同的输出-因此函数不是内射的。如果这将是一个真正的产品,考虑到安全性,请获得一些专家帮助-我已经可以告诉您,您的产品将根本不安全!(例如:在散列之前,你应该在你的密码中添加盐,MD5是一种)@shafay用于加密你的密码我会说没有用或类似的话。。。但是真的:不要自己实现加密/安全性(只有这么多人不适用此规则-我除外)-(从我上面链接的讨论中很容易找到此链接-但就这样吧)好的。。谢谢大家!
PasswordDeriveBytes
是i