Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFastSpringFormValidator.cs
More file actions
Latest commit
executable file
·60 lines (49 loc) · 1.67 KB
/
Copy pathFastSpringFormValidator.cs
File metadata and controls
executable file
·60 lines (49 loc) · 1.67 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
usingSystem;
usingSystem.Collections.Specialized;
usingSystem.Linq;
usingSystem.Security.Cryptography;
usingSystem.Text;
namespaceSyntaxTree.FastSpring
{
internalstaticclassFastSpringFormValidator
{
publicstaticboolIsValidNotification(thisNameValueCollectionform,stringprivateKey)
{
conststringdataParameter="security_data";
conststringhashParameter="security_hash";
if(!form.HasParameter(dataParameter)||!form.HasParameter(hashParameter))
returnfalse;
varvalue=form[dataParameter]+privateKey;
returnform.HashMatches(hashParameter,value);
}
publicstaticboolIsValidLicenseRequest(thisNameValueCollectionform,stringprivateKey)
{
conststringhashParameter="security_request_hash";
if(!form.HasParameter(hashParameter))
returnfalse;
varvalue=form.AllKeys
.Where(k =>k!=hashParameter)
.OrderBy(k =>k,StringComparer.Ordinal)
.Select(k =>form[k])
.Aggregate(newStringBuilder(),(sb,v)=>sb.Append(v))
.Append(privateKey)
.ToString();
returnform.HashMatches(hashParameter,value);
}
privatestaticboolHashMatches(thisNameValueCollectionform,stringhashParameter,stringvalue)
{
returnform[hashParameter].ToLowerInvariant()==Md5HashOf(value);
}
privatestaticboolHasParameter(thisNameValueCollectionform,stringparameter)
{
returnform[parameter]!=null;
}
privatestaticstringMd5HashOf(stringvalue)
{
returnMD5.Create()
.ComputeHash(Encoding.UTF8.GetBytes(value))
.Aggregate(newStringBuilder(),(sb,b)=>sb.Append(b.ToString("x2")))
.ToString();
}
}
}