mirror of
https://github.com/Brandon-Rozek/website-theme.git
synced 2024-11-27 10:28:02 -05:00
40 lines
1.6 KiB
HTML
40 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>
|
|
function encrypt() {
|
|
let textarea = document.querySelector("#pgpcleartext");
|
|
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;
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
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>
|