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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
Imports System
Imports System.IO
Imports System.Security
Imports System.Security.Cryptography
Imports System.Text
Public Class Form6
Dim NumIndex As Integer
Dim guid1 As New Guid
Dim guidid As New Guid
Dim guidmdp As New Guid
Dim path As String = ""
Dim path2 As String = ""
Dim pathnew As String = ""
Dim pathnew2 As String = ""
'Doit correspondre à 64 bits, 8 octets.
Private Const sSecretKey As String = "Password"
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If MsgBox("Etes-vous sur de vouloir tout supprimer ?", vbYesNo + MsgBoxStyle.Exclamation) = MsgBoxResult.Yes Then
ListBox1.Items.Clear()
ListBox2.Items.Clear()
Else
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If MsgBox("Etes-vous sûr de vouloir quitter ? Tout élément non sauvegardé sera perdu.", vbYesNo + MsgBoxStyle.Exclamation) = MsgBoxResult.Yes Then
Application.Exit()
Else
End If
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Form7.Show()
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
NumIndex = ListBox1.SelectedIndex
Try
ListBox1.Items.RemoveAt(NumIndex)
ListBox2.Items.RemoveAt(NumIndex)
Catch ex As Exception
MsgBox("Impossible de supprimer le mot de passe. Vérifiez qu'un élément est bien sélectionné")
End Try
End Sub
Private Sub Form6_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Call CreateVerifFolder()
Label1.Parent = PictureBox1
Label2.Parent = PictureBox1
End Sub
Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
If MsgBox("Etes-vous sur de vouloir supprimer votre compte ?" + vbCrLf + "Une fois celui-ci supprimer, vous ne pourrez pas le récupérer.", vbYesNo + MsgBoxStyle.Exclamation) = MsgBoxResult.Yes Then
Call supp()
Else
End If
End Sub
Sub supp()
Try
'delete save files
Try
'suppression des anciens fichiers .lok
My.Computer.FileSystem.DeleteDirectory(My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + My.Settings.guid1.ToString + "\", FileIO.RecycleOption.DeletePermanently)
Catch ex As Exception
MsgBox("Impossible de supprimer les anciens fichiers")
End Try
'delete items
ListBox1.Items.Clear()
ListBox2.Items.Clear()
'delete settings
My.Settings.Id = ""
My.Settings.Mdp = ""
My.Settings.saltid = ""
My.Settings.saltmdp = ""
My.Settings.Vf = 0
My.Settings.guid1 = Nothing
My.Settings.guidid = Nothing
My.Settings.guidmdp = Nothing
My.Settings.Save()
MsgBox("Compte supprimé avec succès. LoockerBox va fermer.", MsgBoxStyle.Information)
Application.Exit()
Catch ex As Exception
MsgBox("Impossible de supprimer le compte. Veuillez réessayer.", MsgBoxStyle.Exclamation)
End Try
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
ListBox2.SelectedIndex = ListBox1.SelectedIndex
End Sub
Private Sub ListBox2_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
ListBox1.SelectedIndex = ListBox2.SelectedIndex
Button3.Enabled = True
End Sub
Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
Call save()
End Sub
Private Sub save()
path = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + My.Settings.guid1.ToString + "\" + My.Settings.guidid.ToString + ".lok"
path2 = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + My.Settings.guid1.ToString + "\" + My.Settings.guidmdp.ToString + ".lok"
pathnew = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + My.Settings.guid1.ToString + "\" + My.Settings.guidid.ToString + "ENC.lok"
pathnew2 = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + My.Settings.guid1.ToString + "\" + My.Settings.guidmdp.ToString + "ENC.lok"
Try
Dim Sw1 As New StreamWriter(path)
Dim Sw2 As New StreamWriter(path2)
'écriture des identifiants
For Each item In ListBox1.Items
Sw1.WriteLine(item)
Next
Sw1.Close()
Call EncryptFile(path, pathnew, sSecretKey)
'écriture des mdp
For Each item In ListBox2.Items
Sw2.WriteLine(item)
Next
Sw2.Close()
Call EncryptFile(path2, pathnew2, sSecretKey)
MsgBox("Bibliothèque sauvegardée avec succès.")
Catch ex As Exception
MsgBox("Impossible d'enregistrer vos données")
End Try
End Sub
Sub CreateVerifFolder()
guid1 = Guid.NewGuid
guidid = Guid.NewGuid
guidmdp = Guid.NewGuid
'verif de l'existence du dossier nommé LoockerBox
If My.Computer.FileSystem.DirectoryExists(My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + My.Settings.guid1.ToString + "\") = True Then
'ajouter gestion If fichiers inexistants
Call loadFile()
Else
'création du dossier LoockerBox
My.Computer.FileSystem.CreateDirectory(My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + guid1.ToString + "\")
My.Settings.guid1 = guid1
My.Settings.guidid = guidid
My.Settings.guidmdp = guidmdp
My.Settings.Save()
End If
End Sub
Sub EncryptFile(ByVal sInputFilename As String, ByVal sOutputFilename As String, ByVal sKey As String)
Try
Dim fsInput As New FileStream(sInputFilename, FileMode.Open, FileAccess.Read)
Dim fsEncrypted As New FileStream(sOutputFilename, FileMode.Create, FileAccess.Write)
Dim DES As New DESCryptoServiceProvider()
'Définit la clé secrète pour l'algorithme DES.
'Une clé de 64 bits et un vecteur d'initialisation sont requis pour ce fournisseur
DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey)
'Définit le vecteur d'initialisation.
DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey)
'crée un crypteur DES à partir de cette instance
Dim desencrypt As ICryptoTransform = DES.CreateEncryptor()
'Crée un flux de cryptage qui transforme le flux de fichier à l'aide du cryptage DES
Dim cryptostream As New CryptoStream(fsEncrypted, desencrypt, CryptoStreamMode.Write)
'Lit le texte du fichier dans le tableau d'octets
Dim bytearrayinput(fsInput.Length - 1) As Byte
fsInput.Read(bytearrayinput, 0, bytearrayinput.Length)
'écrit le fichier crypté à l'aide de DES
cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length)
cryptostream.Close()
Catch ex As Exception
MsgBox("Erreur dans le cryptage des données. Veuillez réessayer.", MsgBoxStyle.Exclamation)
My.Computer.FileSystem.DeleteDirectory(My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + My.Settings.guid1.ToString + "\", FileIO.RecycleOption.DeletePermanently)
End Try
End Sub
Sub DecryptFile(ByVal sInputFilename As String, ByVal sOutputFilename As String, ByVal sKey As String)
Try
Dim DES As New DESCryptoServiceProvider()
'Une clé de 64 bits et un vecteur d'initialisation sont requis pour ce fournisseur.
'Définit la clé secrète pour l'algorithme DES.
DES.Key() = ASCIIEncoding.ASCII.GetBytes(sKey)
'Définit le vecteur d'initialisation.
DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey)
'crée un flux de fichier pour lire le fichier crypté de retour
Dim fsread As New FileStream(sInputFilename, FileMode.Open, FileAccess.Read)
'crée un décrypteur DES à partir de l'instance DES
Dim desdecrypt As ICryptoTransform = DES.CreateDecryptor()
'crée un flux de cryptage, défini pour lire et effectuer une transformation
Dim cryptostreamDecr As New CryptoStream(fsread, desdecrypt, CryptoStreamMode.Read)
'imprime le contenu du fichier décrypté
Dim fsDecrypted As New StreamWriter(sOutputFilename)
fsDecrypted.Write(New StreamReader(cryptostreamDecr).ReadToEnd)
fsDecrypted.Flush()
fsDecrypted.Close()
Catch ex As Exception
MsgBox("Erreur dans le décryptage des données. L'application va se fermer.", MsgBoxStyle.Exclamation)
Application.Exit()
End Try
End Sub
Sub loadFile()
path = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + My.Settings.guid1.ToString + "\" + My.Settings.guidid.ToString + ".lok"
path2 = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + My.Settings.guid1.ToString + "\" + My.Settings.guidmdp.ToString + ".lok"
pathnew = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + My.Settings.guid1.ToString + "\" + My.Settings.guidid.ToString + "ENC.lok"
pathnew2 = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\LoockerBox\MyLoock\Files\" + My.Settings.guid1.ToString + "\" + My.Settings.guidmdp.ToString + "ENC.lok"
Try
'décryptage identifiant
Call DecryptFile(pathnew, path, sSecretKey)
Dim sr1 As New StreamReader(path)
Dim Split1
Dim ListId As String = ""
While sr1.Peek >= 0
Split1 = sr1.ReadLine.Split(vbCrLf)
ListId = Split1(0)
ListBox1.Items.Add(ListId)
End While
sr1.Close()
'décryptage mdp
Call DecryptFile(pathnew2, path2, sSecretKey)
Dim sr2 As New StreamReader(path2)
Dim Split2
Dim ListMdp As String = ""
While sr2.Peek >= 0
Split2 = sr2.ReadLine.Split(vbCrLf)
ListMdp = Split2(0)
ListBox2.Items.Add(ListMdp)
End While
sr2.Close()
Catch ex As Exception
MsgBox("Erreur lors du décryptage ou de la lecture. Veuillez réessayer.")
End Try
End Sub
End Class |
Partager