-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass1.vb
More file actions
78 lines (78 loc) · 3.11 KB
/
Copy pathClass1.vb
File metadata and controls
78 lines (78 loc) · 3.11 KB
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
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Security.Cryptography
Imports System.Security
Imports System.IO
Imports System
Imports System.ComponentModel
Class EncDec
Public Shared sth As Integer = 0
Public Shared s As Integer
Public Shared Sub Enc(ByVal inputFile As String, ByVal outputFile As String, ByVal passwordBytes As Byte())
Dim saltBytes As Byte() = New Byte() {1, 2, 3, 4, 5, 6, 7, 8}
Dim cryptFile As String = outputFile
Dim fsCrypt As New FileStream(cryptFile, FileMode.Create)
Dim AES As New RijndaelManaged()
AES.KeySize = 256
AES.BlockSize = 128
Dim key = New Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000)
AES.Key = key.GetBytes(AES.KeySize / 8)
AES.IV = key.GetBytes(AES.BlockSize / 8)
AES.Padding = PaddingMode.Zeros
AES.Mode = CipherMode.CBC
Dim cs As New CryptoStream(fsCrypt, AES.CreateEncryptor(), CryptoStreamMode.Write)
Dim fsIn As New FileStream(inputFile, FileMode.Open)
Dim data As Byte() = New Byte(12342) {}
s = My.Computer.FileSystem.GetFileInfo(inputFile).Length
Dim ex As Byte() = {212, 245, 1, 43}
cs.WriteByte(ex(0))
cs.WriteByte(ex(1))
cs.WriteByte(ex(2))
cs.WriteByte(ex(3))
While (fsIn.Read(data, 0, data.Length)) <> 0
cs.Write(data, 0, data.Length)
sth = sth + data.Length
End While
sth = 0
fsIn.Close()
cs.Close()
fsCrypt.Close()
End Sub
Public Shared Sub Dec(ByVal inputFile As String, ByVal outputFile As String, ByVal passwordBytes As Byte())
Dim saltBytes As Byte() = New Byte() {1, 2, 3, 4, 5, 6, 7, 8}
Dim fsCrypt As New FileStream(inputFile, FileMode.Open)
Dim AES As New RijndaelManaged()
AES.KeySize = 256
AES.BlockSize = 128
Dim key = New Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000)
AES.Key = key.GetBytes(AES.KeySize / 8)
AES.IV = key.GetBytes(AES.BlockSize / 8)
AES.Padding = PaddingMode.Zeros
AES.Mode = CipherMode.CBC
Dim cs As New CryptoStream(fsCrypt, AES.CreateDecryptor(), CryptoStreamMode.Read)
Dim fsOut As New FileStream(outputFile, FileMode.Create)
Dim data As Byte() = New Byte(12342) {}
s = My.Computer.FileSystem.GetFileInfo(inputFile).Length
Dim ex = {0, 0, 0, 0}
ex(0) = cs.ReadByte()
ex(1) = cs.ReadByte()
ex(2) = cs.ReadByte()
ex(3) = cs.ReadByte()
If ex(0) = 212 And ex(1) = 245 And ex(2) = 1 And ex(3) = 43 Then
While (cs.Read(data, 0, data.Length)) <> 0
fsOut.Write(data, 0, data.Length)
sth = sth + 1
End While
Else
frmNew.st = 1
End If
sth = 0
fsOut.Close()
cs.Close()
fsCrypt.Close()
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
End Class