This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
utils.asp
81 lines (63 loc) · 2.36 KB
/
utils.asp
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
<!--#include file="external/base64.asp"-->
<!--#include file="external/aspJSON.asp"-->
<%
' The URL- and filename-safe Base64 encoding described in RFC 4648 [RFC4648], Section 5,
' with the (non URL-safe) '=' padding characters omitted, as permitted by Section 3.2.
' (See Appendix C of [JWS] for notes on implementing base64url encoding without padding.)
' http://tools.ietf.org/html/rfc4648
' http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-10
Function SafeBase64Encode(sIn)
sOut = Base64Encode(sIn)
sOut = Base64ToSafeBase64(sOut)
SafeBase64Encode = sOut
End Function
' Strips unsafe characters from a Base64 encoded string
Function Base64ToSafeBase64(sIn)
sOut = Replace(sIn,"+","-")
sOut = Replace(sOut,"/","_")
sOut = Replace(sOut,"\r","")
sOut = Replace(sOut,"\n","")
sOut = Replace(sOut,"=","")
Base64ToSafeBase64 = sOut
End Function
' Converts an ASP dictionary to a JSON string
Function DictionaryToJSONString(dDictionary)
Set oJSONpayload = New aspJSON
Dim i, aKeys
aKeys = dDictionary.keys
For i = 0 to dDictionary.Count-1
oJSONpayload.data (aKeys(i))= dDictionary(aKeys(i))
Next
DictionaryToJSONString = oJSONpayload.JSONoutput()
End Function
Function dtmAdjusted_date()
Dim dtmDateValue, dtmAdjusted
Dim objShell, lngBiasKey, lngBias, k
dtmDateValue = Now()
' Obtain local Time Zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _
& "TimeZoneInformation\ActiveTimeBias")
If (UCase(TypeName(lngBiasKey)) = "LONG") Then
lngBias = lngBiasKey
ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then
lngBias = 0
For k = 0 To UBound(lngBiasKey)
lngBias = lngBias + (lngBiasKey(k) * 256^k)
Next
End If
' Convert datetime value to UTC.
dtmAdjusted = DateAdd("n", lngBias, dtmDateValue)
dtmAdjusted_date = dtmAdjusted
End Function
' Returns the number of seconds since epoch
Function SecsSinceEpoch()
SecsSinceEpoch = DateDiff("s", "01/01/1970 00:00:00", dtmAdjusted_date())
End Function
' Returns a random string to prevent replays
Function UniqueString()
Set TypeLib = CreateObject("Scriptlet.TypeLib")
UniqueString = Left(CStr(TypeLib.Guid), 38)
Set TypeLib = Nothing
End Function
%>