This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
forked from TheAlphaSchoolSystemPTYLTD/api-introduction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencryptDecrypt.cfm
59 lines (40 loc) · 1.72 KB
/
encryptDecrypt.cfm
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
<cfset endPoint = "http://api.tasscloud.com.au/tassweb/api/">
<cfset method = "getStudents">
<cfset appCode = "DEMOAPP">
<cfset companyCode = "10">
<cfset version = "2">
<cfset tokenKey = "x8FWQUedjyiUGlTf5appPQ==">
<cfset parameterString = '{"include_label":"true"}'>
<cfset encryptedString = letsEncrypt(stringToEncrypt=parameterString,tokenKey=tokenKey)>
<cfoutput>
<p>Original: #parameterString#</p>
<p>Encrypted: #letsEncrypt(stringToEncrypt=parameterString,tokenKey=tokenKey)#</p>
<p>Decrypted: #letsDecrypt(stringToDecrypt=encryptedString,tokenKey=tokenKey)#</p>
<p>URL: #endpoint#?method=#method#&appcode=#appCode#&company=#companyCode#&v=#version#&token=#urlEncodedFormat(encryptedString)#</p>
</cfoutput>
<cffunction name="letsEncrypt">
<cfargument name="stringToEncrypt" required="true">
<cfargument name="tokenKey" required="true">
<cfargument name="algorithm" required="false" default="AES">
<cfargument name="encoding" required="false" default="Base64">
<cfset var encryptedString = Encrypt(
arguments.stringToEncrypt,
arguments.tokenKey,
arguments.algorithm,
arguments.encoding
)>
<cfreturn encryptedString>
</cffunction>
<cffunction name="letsDecrypt">
<cfargument name="stringToDecrypt" required="true">
<cfargument name="tokenKey" required="true">
<cfargument name="algorithm" required="false" default="AES">
<cfargument name="encoding" required="false" default="Base64">
<cfset var decryptedString = Decrypt(
arguments.stringToDecrypt,
arguments.tokenKey,
arguments.algorithm,
arguments.encoding
)>
<cfreturn decryptedString>
</cffunction>