-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcrypto-js.html
26 lines (24 loc) · 1.01 KB
/
crypto-js.html
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
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/hmac-sha256.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/enc-base64.min.js"></script>
<script>
function getParameterByName(name, url = window.location.href) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
var message = getParameterByName('message');
var secret = getParameterByName('secret');
var secretDecoded = CryptoJS.enc.Base64.parse(secret);
var hash = CryptoJS.HmacSHA256(message, secretDecoded);
var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
var response = {
signature: hashInBase64
};
document.write(JSON.stringify(response));
</script>
</html>