1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| Private Sub cmdChangePass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChangePass.Click
If String.Compare(Me.txtNewPass.Text, Me.txtConfirm.Text, False) <> 0 Then
MsgBox("la confirmation à échoué")
Exit Sub
End If
Dim fFichier As New System.IO.StreamWriter(Application.StartupPath & "\ctrl.sec", False)
Dim bitHachage As Byte()
Dim wCode As New System.Text.UnicodeEncoding
Dim bitPass() As Byte = wCode.GetBytes(Me.txtNewPass.Text)
Dim sha1Hachage As New Security.Cryptography.SHA1CryptoServiceProvider
bitHachage = sha1Hachage.ComputeHash(bitPass)
fFichier.WriteLine(Convert.ToBase64String(bitHachage))
Dim pdb As New Security.Cryptography.PasswordDeriveBytes(Me.txtNewPass.Text, New Byte(7) {21, 10, 16, 21, 32, 2, 78, 9}, "SHA1", 1000)
Dim DES3Code As New System.Security.Cryptography.TripleDESCryptoServiceProvider
With DES3Code
.Key = pdb.GetBytes(16)
.IV = pdb.GetBytes(8)
End With
Dim fMem As New System.IO.MemoryStream
Dim fCrypt As New Security.Cryptography.CryptoStream(fMem, DES3Code.CreateEncryptor, Security.Cryptography.CryptoStreamMode.Write)
fCrypt.Write(bitPass, 0, bitPass.Length)
fCrypt.Close()
fFichier.WriteLine(Convert.ToBase64String(fMem.ToArray))
fFichier.Flush()
fFichier.Close()
End Sub |
Partager