mirror of
https://github.com/Brandon-Rozek/website-theme.git
synced 2024-11-23 16:46:37 -05:00
PGP Form
This commit is contained in:
parent
65bd1c7721
commit
5142aa6012
2 changed files with 55 additions and 0 deletions
17
assets/js/openpgp.min.js
vendored
Normal file
17
assets/js/openpgp.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
38
layouts/shortcodes/pgpform.html
Normal file
38
layouts/shortcodes/pgpform.html
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
{{- $openPGP := resources.Get "js/openpgp.min.js" -}}
|
||||||
|
<script src="{{ $openPGP.Permalink }}"></script>
|
||||||
|
<textarea id="pgpform" style="width: 100%; min-height: 10rem;"></textarea>
|
||||||
|
<script>
|
||||||
|
function encrypt() {
|
||||||
|
let textarea = document.querySelector("#pgpform");
|
||||||
|
let pubKeyURL = "{{ .Get 0 }}"
|
||||||
|
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) {
|
||||||
|
textarea.value = encryptedMessage
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function copyToClipboard() {
|
||||||
|
let textarea = document.querySelector("#pgpform");
|
||||||
|
textarea.select();
|
||||||
|
let successful = document.execCommand('copy');
|
||||||
|
}
|
||||||
|
function genEmail() {
|
||||||
|
let textarea = document.querySelector("#pgpform");
|
||||||
|
let contents = textarea.value;
|
||||||
|
let encodedContents = encodeURIComponent(contents);
|
||||||
|
let encodedSubject = encodeURIComponent("Contact Form")
|
||||||
|
window.location.href = "mailto:{{ .Site.Params.email }}?subject=" +
|
||||||
|
encodedSubject + "&body=" + encodedContents;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<button onclick="encrypt()">Encrypt</button><button onclick="copyToClipboard()">Copy</button><button onclick="genEmail()">Generate Email</button>
|
Loading…
Reference in a new issue