forked from zendesk/classic_asp_jwt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.asp
70 lines (59 loc) · 2.04 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
<!--#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)
Dim sOut
sOut = Base64Encode(sIn)
sOut = Base64ToSafeBase64(sOut)
SafeBase64Encode = sOut
End Function
' Strips unsafe characters from a Base64 encoded string
Function Base64ToSafeBase64(sIn)
Dim sOut
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)
Dim oJSONpayload
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
%>
<script language='Javascript' runat='server'>
function jsGetUTCTime() {
var d = new Date();
return (d.getUTCMonth() + 1) + "/" + d.getUTCDate() + "/" + d.getUTCFullYear()
+ " " + d.getUTCHours() + ":" + d.getUTCMinutes() + ":" + d.getUTCSeconds();
}
</script>
<script language='VBScript' runat='server'>
Function getUTCTime()
' Use JavaScript to get the current GMT time stamp
getUTCTime = jsGetUTCTime()
End Function
</script>
<%
' Returns the number of seconds since epoch
Function SecsSinceEpoch()
SecsSinceEpoch = DateDiff("s", "01/01/1970 00:00:00", getUTCTime())
End Function
' Returns a random string to prevent replays
Function UniqueString()
UniqueString = Left(CStr(CreateObject("Scriptlet.TypeLib").Guid), 38)
End Function
%>