website-theme/layouts/shortcodes/pgpform.html

41 lines
1.6 KiB
HTML
Raw Permalink Normal View History

2022-12-14 21:49:46 -05:00
{{- $openPGP := resources.Get "js/openpgp.min.js" -}}
<script src="{{ $openPGP.Permalink }}"></script>
2022-12-18 18:03:16 -05:00
<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>
2022-12-14 21:49:46 -05:00
<script>
function encrypt() {
2022-12-18 18:03:16 -05:00
let textarea = document.querySelector("#pgpcleartext");
let resultarea = document.querySelector('#pgpresult');
2022-12-24 19:44:46 -05:00
let pubKeyURL = "{{ .Get 0 }}";
resultarea.textContent = "";
2022-12-14 21:49:46 -05:00
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]
2022-12-24 19:44:46 -05:00
};
2022-12-14 21:49:46 -05:00
return openpgp.encrypt(encryptionParameters).then(function(encryptedMessage) {
2022-12-24 19:44:46 -05:00
resultarea.textContent = encryptedMessage;
2022-12-14 21:49:46 -05:00
});
});
});
});
}
2022-12-18 18:03:16 -05:00
2022-12-14 21:49:46 -05:00
function genEmail() {
2022-12-18 18:03:16 -05:00
let resultarea = document.querySelector('#pgpresult');
let contents = resultarea.textContent;
2022-12-14 21:49:46 -05:00
let encodedContents = encodeURIComponent(contents);
2022-12-24 19:44:46 -05:00
let encodedSubject = encodeURIComponent("Contact Form");
2022-12-14 21:49:46 -05:00
window.location.href = "mailto:{{ .Site.Params.email }}?subject=" +
encodedSubject + "&body=" + encodedContents;
}
</script>
2022-12-18 18:03:16 -05:00
<button class="pgpbutton" onclick="genEmail()">Generate Email</button>