mirror of
https://github.com/Brandon-Rozek/website-theme.git
synced 2025-07-30 05:32:00 +00:00
Added verification to contact form
This commit is contained in:
parent
bd7e11b421
commit
6c189eb8f2
2 changed files with 65 additions and 18 deletions
|
@ -6,26 +6,34 @@
|
|||
Encrypted Result:
|
||||
<pre id="pgpresult" class="pgpform"></pre>
|
||||
<script>
|
||||
function encrypt() {
|
||||
let textarea = document.querySelector("#pgpcleartext");
|
||||
async function encrypt() {
|
||||
let resultarea = document.querySelector('#pgpresult');
|
||||
let pubKeyURL = "{{ .Get 0 }}";
|
||||
resultarea.textContent = "";
|
||||
fetch(pubKeyURL).then(function(response) {
|
||||
return response.text().then(function(text) {
|
||||
const pubKey = openpgp.readKey({ armoredKey: text });
|
||||
const message = openpgp.createMessage({ text: textarea.value })
|
||||
return Promise.all([message, pubKey]).then(function(mp) {
|
||||
const encryptionParameters = {
|
||||
message: mp[0],
|
||||
encryptionKeys: mp[1]
|
||||
};
|
||||
return openpgp.encrypt(encryptionParameters).then(function(encryptedMessage) {
|
||||
resultarea.textContent = encryptedMessage;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
let textarea = document.querySelector("#pgpcleartext");
|
||||
if (textarea.value.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let pubKeyURL = "{{ .Get 0 }}";
|
||||
let pubKey;
|
||||
|
||||
try {
|
||||
const response = await fetch(pubKeyURL);
|
||||
const text = await response.text();
|
||||
pubKey = await openpgp.readKey({ armoredKey: text });
|
||||
} catch {
|
||||
resultarea.textContent = "Error: Unable to obtain key";
|
||||
}
|
||||
|
||||
try {
|
||||
const message = await openpgp.createMessage({ text: textarea.value });
|
||||
const encryptedMessage = await openpgp.encrypt({message: message, encryptionKeys: pubKey});
|
||||
resultarea.textContent = encryptedMessage;
|
||||
} catch {
|
||||
resultarea.textContent = "Error: Unable to encrypt message"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function genEmail() {
|
||||
|
|
39
layouts/shortcodes/pgpverify.html
Normal file
39
layouts/shortcodes/pgpverify.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
{{- $openPGP := resources.Get "js/openpgp.min.js" -}}
|
||||
<script src="{{ $openPGP.Permalink }}"></script>
|
||||
<textarea id="pgpsignedtext" class="pgpform" style="width: 100%; min-height: 10rem;"></textarea>
|
||||
<button class="pgpverifybutton" onclick="verify()">Verify</button>
|
||||
<br/>
|
||||
Verification Result:
|
||||
<pre id="pgpverifyresult" class="pgpform"></pre>
|
||||
<script>
|
||||
async function verify() {
|
||||
let resultarea = document.querySelector('#pgpverifyresult');
|
||||
resultarea.textContent = "";
|
||||
|
||||
let textarea = document.querySelector("#pgpsignedtext");
|
||||
if (textarea.value.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let pubKeyURL = "{{ .Get 0 }}";
|
||||
let pubKey;
|
||||
|
||||
try {
|
||||
const response = await fetch(pubKeyURL);
|
||||
const text = await response.text();
|
||||
pubKey = await openpgp.readKey({ armoredKey: text });
|
||||
} catch {
|
||||
resultarea.textContent = "Error: Unable to obtain key";
|
||||
}
|
||||
|
||||
try {
|
||||
const message = await openpgp.readCleartextMessage({ cleartextMessage: textarea.value });
|
||||
const verifyResult = await openpgp.verify({message: message, verificationKeys: pubKey});
|
||||
const validResult = await verifyResult.signatures[0].verified;
|
||||
resultarea.textContent = (validResult)? "Valid": "Invalid";
|
||||
} catch {
|
||||
resultarea.textContent = "Invalid";
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
Loading…
Add table
Reference in a new issue