Import IO and Security.Cryptography
File Decryption
Dim ue As New UnicodeEncoding()
Dim key As Byte() = ue.GetBytes(pword)
Dim rm As New RijndaelManaged()
Dim fs1 As New FileStream(file_path, FileMode.Open)
path = save_path
Dim str As String(), st As String()
str = file_path.Split("\"c)
Dim str1 As String = str(str.Length - 1)
st = str1.Split("."c)
save_path = path & "\" & st(0) + "." & st(1)
Dim i As Integer = 0
Dim fs2 As New FileStream(save_path, FileMode.Create)
Dim cs As New CryptoStream(fs2, rm.CreateDecryptor(key, key), CryptoStreamMode.Write)
While (True)
Dim d As Integer
d = fs1.ReadByte()
If d = -1 Then
Exit While
End If
cs.WriteByte(Convert.ToByte(d))
End While
cs.Close()
fs1.Close()
File Encryption
Dim ue As New UnicodeEncoding()
Dim key As Byte() = ue.GetBytes(pword)
Dim rm As New RijndaelManaged()
Dim fs1 As New FileStream(file_path, FileMode.Open)
path = save_path
Dim str As String(), st As String()
str = file_path.Split("\"c)
Dim str1 As String = str(str.Length - 1)
save_path = path + "\" + str1 + ".cpt"
Dim i As Integer = 0
While (True)
If File.Exists(save_path) Then
st = str1.Split("."c)
i = i + 1
save_path = path + "\" & st(0) & "(" & i & ")" & "." & st(1) & ".cpt"
Else
Exit While
End If
End While
Dim fs2 As New FileStream(save_path, FileMode.Create)
Dim cs As New CryptoStream(fs2, rm.CreateEncryptor(key, key), CryptoStreamMode.Write)
While (True)
Dim d As Integer
d = fs1.ReadByte()
If d = -1 Then
Exit While
End If
cs.WriteByte(Convert.ToByte(d))
End While
cs.Close()
fs1.Close()
No comments:
Post a Comment