Skip to content

Instantly share code, notes, and snippets.

@alhimik45
Created January 2, 2018 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alhimik45/5283b511d0c08698e40f43235373ec3c to your computer and use it in GitHub Desktop.
Save alhimik45/5283b511d0c08698e40f43235373ec3c to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Passgen</title>
</head>
<body>
<center>
<p id="hahash">_</p>
<input type="password" id="master"><button onclick="masterinp();">Ok</button><br/><br/>
<input type="password" id="local"><br/><br/>
<input type="password" id="localr"><button onclick="localinp()">Ok</button><br/><br/>
</center>
<script type="text/javascript">
function sha256(str) {
var buffer = new TextEncoder("utf-8").encode(str);
return crypto.subtle.digest("SHA-256", buffer).then(function (hash) {
return hex(hash);
});
}
function sha512(str) {
var buffer = new TextEncoder("utf-8").encode(str);
return crypto.subtle.digest("SHA-512", buffer).then(function (hash) {
return hex(hash);
});
}
function hex(buffer) {
var hexCodes = [];
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 4) {
var value = view.getUint32(i)
var stringValue = value.toString(16)
var padding = '00000000'
var paddedValue = (padding + stringValue).slice(-padding.length)
hexCodes.push(paddedValue);
}
var s = hexCodes.join("");
return s;
}
let m="";
async function masterinp() {
m = await sha512(document.querySelector("#master").value)
document.querySelector("#master").value = "";
document.querySelector("#hahash").innerHTML = await sha256(m)
}
async function localinp() {
var loc = await sha512(document.querySelector("#local").value)
var locr = await sha512(document.querySelector("#localr").value)
if(loc != locr){
alert("Local keys not identical")
return
}
prompt("", await sha256(m + loc))
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment