Skip to content

Commit

Permalink
Use CryptoJS to overcome SSL restriction from Crypto API
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user authored Jan 28, 2024
1 parent 3a8cad3 commit 55dbf25
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pystream/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<meta name="image" property="og:image" content="https://thevickypedia.com/img/apple-touch-icon.jpg">
<meta content="width=device-width, initial-scale=1" name="viewport">
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>
<!-- Disables 404 for favicon.ico which is a logo on top of the webpage tab -->
<link rel="shortcut icon" href="#">
<!-- Font Awesome icons -->
Expand Down Expand Up @@ -125,9 +126,17 @@
const message = username + password + timestamp;
const encoder = new TextEncoder();
const data = encoder.encode(message);
const hashBuffer = await crypto.subtle.digest('SHA-512', data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
if (crypto.subtle === undefined) {
const wordArray = CryptoJS.lib.WordArray.create(data);
const hash = CryptoJS.SHA512(wordArray);
// Convert the hash to a hexadecimal string and return it
return hash.toString(CryptoJS.enc.Hex);
} else {
const hashBuffer = await crypto.subtle.digest('SHA-512', data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
// Convert each byte to a hexadecimal string, pad with zeros, and join them to form the final hash
return hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
}
}
let hex_user = await ConvertStringToHex(username);
let hex_pass = await ConvertStringToHex(password);
Expand Down

0 comments on commit 55dbf25

Please sign in to comment.