- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationSecurity.vb
More file actions
Latest commit
125 lines (108 loc) · 5.56 KB
/
Copy pathApplicationSecurity.vb
File metadata and controls
125 lines (108 loc) · 5.56 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
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
' WWWeb Concepts wwwebconcepts.com
' James W. Threadgill james@wwwebconcepts.com
' Copyright 2017
' Version 1.0.0.0
'=========================================================================================================================================================
' MIT License
' Copyright(c) 2017 James Threadgill
' Permission Is hereby granted, free Of charge, to any person obtaining a copy of this software And associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, And/Or sell
' copies of the Software, And to permit persons to whom the Software Is'furnished to do so, subject to the following conditions:
'
' The above copyright notice And this permission notice shall be included In all copies Or substantial portions Of the Software.
'
' THE SOFTWARE Is PROVIDED "AS IS", WITHOUT WARRANTY Of ANY KIND, EXPRESS Or IMPLIED, INCLUDING BUT Not LIMITED To THE WARRANTIES Of MERCHANTABILITY,
' FITNESS For A PARTICULAR PURPOSE And NONINFRINGEMENT. In NO Event SHALL THE AUTHORS Or COPYRIGHT HOLDERS BE LIABLE For ANY CLAIM, DAMAGES Or OTHER
' LIABILITY, WHETHER In AN ACTION Of CONTRACT, TORT Or OTHERWISE, ARISING FROM, OUT OF Or IN CONNECTION WITH THE SOFTWARE Or THE USE Or OTHER DEALINGS
' IN THE SOFTWARE.
'=============================================================================================================================================================
ImportsSystem.IO
ImportsSystem.Net
ImportsSystem.Text
ImportsSystem.Convert
ImportsSystem.Web.HttpContext
ImportsSystem.Security.Cryptography
ImportsSystem.Text.RegularExpressions.Regex
' site security utilities
PublicClassApplicationSecurity
' Filter user input for malicious code and remove
PublicSharedFunctionValidateInput(ByValinputStringAsString)AsString
IfinputString<>""Then
inputString=Replace(inputString,"[^aA-zZ0-9\s-\]"," ")
inputString=Replace(inputString,"\s+"," ").Trim()
EndIf
ReturninputString
EndFunction
' base 64 querystring encoding for data security
ConstsBASE_64_CHARACTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-"
'Encode
PublicSharedFunctionEncode(ByValasContentsAsString)AsString
IfInitializeApplication.EncodeIDs()Then
DimlnPositionAsInteger
DimlsResultAsString
DimChar1AsString
DimChar2AsString
DimChar3AsString
DimChar4AsString
DimByte1AsString
DimByte2AsString
DimByte3AsString
DimSaveBits1AsString
DimSaveBits2AsString
DimlsGroupBinaryAsString
DimlsGroup64AsString
IfLen(asContents)Mod3>0ThenasContents=asContents&StrDup(3-(Len(asContents)Mod3)," ")
lsResult=""
ForlnPosition=1ToLen(asContents)Step3
lsGroup64=""
lsGroupBinary=Mid(asContents,lnPosition,3)
Byte1=Asc(Mid(lsGroupBinary,1,1)):SaveBits1=Byte1And3
Byte2=Asc(Mid(lsGroupBinary,2,1)):SaveBits2=Byte2And15
Byte3=Asc(Mid(lsGroupBinary,3,1))
Char1=Mid(sBASE_64_CHARACTERS,((Byte1And252)\4)+1,1)
Char2=Mid(sBASE_64_CHARACTERS,(((Byte2And240)\16)Or(SaveBits1*16)And&HFF)+1,1)
Char3=Mid(sBASE_64_CHARACTERS,(((Byte3And192)\64)Or(SaveBits2*4)And&HFF)+1,1)
Char4=Mid(sBASE_64_CHARACTERS,(Byte3And63)+1,1)
lsGroup64=Char1&Char2&Char3&Char4
lsResult&=lsGroup64
Next
ReturnlsResult
Else
ReturnasContents
EndIf
EndFunction
'decode
PublicSharedFunctionDecode(ByValasContentsAsString)AsString
IfInitializeApplication.EncodeIDs()Then
DimlnPositionAsInteger
DimlsResultAsString
DimChar1AsString
DimChar2AsString
DimChar3AsString
DimChar4AsString
DimByte1AsString
DimByte2AsString
DimByte3AsString
DimlsGroupBinaryAsString
DimlsGroup64AsString
IfLen(asContents)Mod4>0ThenasContents=asContents&StrDup(4-(Len(asContents)Mod4)," ")
lsResult=""
ForlnPosition=1ToLen(asContents)Step4
lsGroupBinary=""
lsGroup64=Mid(asContents,lnPosition,4)
Char1=InStr(sBASE_64_CHARACTERS,Mid(lsGroup64,1,1))-1
Char2=InStr(sBASE_64_CHARACTERS,Mid(lsGroup64,2,1))-1
Char3=InStr(sBASE_64_CHARACTERS,Mid(lsGroup64,3,1))-1
Char4=InStr(sBASE_64_CHARACTERS,Mid(lsGroup64,4,1))-1
Byte1=Chr(((Char2And48)\16)Or(Char1*4)And&HFF)
Byte2=lsGroupBinary&Chr(((Char3And60)\4)Or(Char2*16)And&HFF)
Byte3=Chr((((Char3And3)*64)And&HFF)Or(Char4And63))
lsGroupBinary=Byte1&Byte2&Byte3
lsResult&=lsGroupBinary
Next
ReturnlsResult
Else
ReturnasContents
EndIf
EndFunction
EndClass