mirror of
https://github.com/Brandon-Rozek/website-theme.git
synced 2025-07-31 14:12:01 +00:00
48 lines
1.6 KiB
HTML
48 lines
1.6 KiB
HTML
{{- $openPGP := resources.Get "js/openpgp.min.js" -}}
|
|
<script src="{{ $openPGP.Permalink }}"></script>
|
|
<textarea id="pgpcleartext" class="pgpform" style="width: 100%; min-height: 10rem;"></textarea>
|
|
<button class="pgpbutton" onclick="encrypt()">Encrypt</button>
|
|
<br/>
|
|
Encrypted Result:
|
|
<pre id="pgpresult" class="pgpform"></pre>
|
|
<script>
|
|
async function encrypt() {
|
|
let resultarea = document.querySelector('#pgpresult');
|
|
resultarea.textContent = "";
|
|
|
|
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() {
|
|
let resultarea = document.querySelector('#pgpresult');
|
|
let contents = resultarea.textContent;
|
|
let encodedContents = encodeURIComponent(contents);
|
|
let encodedSubject = encodeURIComponent("Contact Form");
|
|
window.location.href = "mailto:{{ .Site.Params.email }}?subject=" +
|
|
encodedSubject + "&body=" + encodedContents;
|
|
}
|
|
</script>
|
|
<button class="pgpbutton" onclick="genEmail()">Generate Email</button>
|