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
|
Private Sub EncryptFile(ByVal Str_Input_File As String, ByVal Str_Output_File As String, ByVal Str_Private_Key As String)
Dim Fl_Stream_Input As New FileStream(Str_Input_File, FileMode.Open, FileAccess.Read)
Dim Fl_Stream_Encrypted As New FileStream(Str_Output_File, FileMode.Create, FileAccess.Write)
Dim DES_Object As New DESCryptoServiceProvider
DES_Object.Key = ASCIIEncoding.ASCII.GetBytes(Str_Private_Key)
DES_Object.IV = ASCIIEncoding.ASCII.GetBytes(Str_Private_Key)
Dim DesEncrypt As ICryptoTransform = DES_Object.CreateEncryptor
Dim Crypto_Stream As New CryptoStream(Fl_Stream_Encrypted, DesEncrypt, CryptoStreamMode.Write)
Dim Byte_Array_Input(Str_Input_File.Length) As Byte
Fl_Stream_Input.Read(Byte_Array_Input, 0, Byte_Array_Input.Length)
Crypto_Stream.Write(Byte_Array_Input, 0, Byte_Array_Input.Length - 1)
Fl_Stream_Input.Flush()
Fl_Stream_Input.Close()
Fl_Stream_Encrypted.Flush()
Fl_Stream_Encrypted.Close()
'Crypto_Stream.Flush()
' Crypto_Stream.Close()
End Sub
Private Sub DecryptFile(ByVal Str_Input_File As String, ByVal Str_Output_File As String, ByVal Str_Key As String)
Dim DES_Object As New DESCryptoServiceProvider
DES_Object.Key = ASCIIEncoding.ASCII.GetBytes(Str_Key)
DES_Object.IV = ASCIIEncoding.ASCII.GetBytes(Str_Key)
Dim Fl_Stream_Input As New FileStream(Str_Input_File, FileMode.Open, FileAccess.Read)
Dim DesDecrypt As ICryptoTransform = DES_Object.CreateDecryptor
Dim Crypto_Stream As New CryptoStream(Fl_Stream_Input, DesDecrypt, CryptoStreamMode.Read)
Dim Fl_Stream_Decrypted As New StreamWriter(Str_Output_File)
Fl_Stream_Decrypted.Write(New StreamReader(Crypto_Stream).ReadToEnd)
Fl_Stream_Decrypted.Flush()
Fl_Stream_Decrypted.Close()
End Sub |
Partager