Imports System.Security.Cryptography Imports System.IO 'http://www.aspsnippets.com/Articles/Encrypt-and-Decrypt-XML-File-using-C-and-VBNet.aspx Public Class Form1 Private Shared Function Assign(Of T)(ByRef source As T, ByVal value As T) As T source = value Return value End Function Private Sub Encrypt(inputFilePath As String, outputfilePath As String) Dim EncryptionKey As String = "MAKV2SPBNI99212" Using encryptor As Aes = Aes.Create() Dim pdb As New Rfc2898DeriveBytes(EncryptionKey, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D, _ &H65, &H64, &H76, &H65, &H64, &H65, _ &H76}) encryptor.Key = pdb.GetBytes(32) encryptor.IV = pdb.GetBytes(16) Using fs As New FileStream(outputfilePath, FileMode.Create) Using cs As New CryptoStream(fs, encryptor.CreateEncryptor(), CryptoStreamMode.Write) Using fsInput As New FileStream(inputFilePath, FileMode.Open) Dim data As Integer While (Assign(data, fsInput.ReadByte())) <> -1 cs.WriteByte(CByte(data)) End While End Using End Using End Using End Using End Sub Private Sub Decrypt(inputFilePath As String, outputfilePath As String) Dim EncryptionKey As String = "MAKV2SPBNI99212" Using encryptor As Aes = Aes.Create() Dim pdb As New Rfc2898DeriveBytes(EncryptionKey, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D, _ &H65, &H64, &H76, &H65, &H64, &H65, _ &H76}) encryptor.Key = pdb.GetBytes(32) encryptor.IV = pdb.GetBytes(16) Using fs As New FileStream(inputFilePath, FileMode.Open) Using cs As New CryptoStream(fs, encryptor.CreateDecryptor(), CryptoStreamMode.Read) Using fsOutput As New FileStream(outputfilePath, FileMode.Create) Dim data As Integer While (Assign(data, cs.ReadByte())) <> -1 fsOutput.WriteByte(CByte(data)) End While End Using End Using End Using End Using End Sub ' Encrypter Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Encrypt("C:\Users\LePivert\Documents\Logiciels\astlog\readme.txt", "C:\Users\LePivert\Documents\monfichiercode.txt")'adapter les chemins End Sub ' Decrypter Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click Decrypt("C:\Users\LePivert\Documents\monfichiercode.txt", "C:\Users\LePivert\Documents\monfichierdecode.txt")'adapter les chemins End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Button1.Text = "Crypter" Button2.Text = "Decrypter" End Sub End Class
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.