Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
151 lines (125 sloc) 4.89 KB
---
title: Send me an encrypted message
permalink: /encrypt
description: Use this tool to encrypt a message so that only I can read it.
---
<!--
Want a page just like this?
1. Copy this html file to your server
2. Upload a public PGP key to be available at /key.asc
3. Update the contact info
-->
<h1>Send me an encrypted message</h1>
<noscript>This tool requires the use of javascript. If you prefer to not use javascript, you can use my public PGP key located at <a href="/key.asc">/key.asc</a>.</noscript>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/openpgp/4.5.5/openpgp.min.js"></script>
<p id="loading-message"></p>
<div id="encryption-form" class="hidden">
<p>
You can use this tool to encrypt a file or message which only I will be able to decrypt.
It uses <a href="https://openpgpjs.org/">OpenPGP.js</a> and <a href="/key.asc">my public key</a>.
</p>
<h3>File Encrypt</h3>
<p>
Select a file to download an encrypted copy you can send to me.
<div class="form-group">
<div class="input-group">
<label for="file">Encrypt File</label>
<div class="file-input">
<label>Select a file to encrypt.</label>
<input name="file" type="file" id="file-input"/>
</div>
</div>
</div>
</p>
<h3>Message Encrypt</h3>
<p>
Use this form to generate an encrypted message. Click the output to copy, or press the link to open it as an email draft.
<div class="form-group">
<div class="input-group">
<label for="name">From</label>
<input type="text" name="name" placeholder="Optional"/>
</div>
<div class="input-group">
<label for="message">Message</label>
<textarea name="message" id="input" placeholder="Enter a message to encrypt." disabled>Public key is not loaded. You cannot use this feature yet.</textarea>
</div>
<label>Encrypted Message</label>
<pre id="output" title="Click here to copy to clipboard">Your encrypted message will appear here.</pre>
<a id="send-link" class="button">Email Link</a>
</div>
</p>
</div>
<script type="text/javascript">
(() => {
let input = document.getElementById('input');
let file = document.getElementById('file-input');
let output = document.getElementById('output');
let name = document.querySelector('input[name="name"]');
let form = document.getElementById('encryption-form');
let send = document.getElementById('send-link');
let pubkey = "";
try { document.getElementById('loading-message').innerText = "This tool is loading..."; } catch {}
fetch("/key.asc")
.then(resp => {
resp.text().then(async (text) => {
pubkey = (await openpgp.key.readArmored(text)).keys;
start();
});
});
let start = () => {
input.disabled = false;
input.innerText = "";
form.classList.remove('hidden');
try { document.getElementById('loading-message').remove(); } catch {}
};
let encrypt = async (plaintext) => {
let options = {
message: openpgp.message.fromBinary(plaintext),
publicKeys: pubkey
};
return await openpgp.encrypt(options);
};
let update_ciphertext = () => {
let message = `From: ${name.value}\nMessage: ${input.value}`
let options = {
message: openpgp.message.fromText(message),
publicKeys: pubkey
};
openpgp.encrypt(options).then(ciphertext => {
output.innerText = ciphertext.data;
});
};
input.addEventListener('keyup', update_ciphertext);
name.addEventListener('keyup', update_ciphertext);
file.addEventListener('change', () => {
let reader = new FileReader;
reader.readAsArrayBuffer(file.files[0]);
reader.onloadend = async () => {
let result = await encrypt(new Uint8Array(reader.result));
let link = document.createElement('a');
link.href = "data:application/octet-stream;base64," + encodeURI(btoa(result.data));
link.setAttribute("download", file.files[0].name + '.gpg');
link.click();
let click = document.createEvent("MouseEvents");
click.initEvent("click", false, true);
link.dispatchEvent(click);
}
});
output.addEventListener('click', () => {
clipboard.copy(output.innerText);
});
send.addEventListener('click', () => {
send.href = "mailto:Jacob Shreve<jacob@shreve.io>?body=" + encodeURI(output.innerText);
});
})();
</script>
<h3>Why is this a thing?</h3>
<p>
I don't really have a good reason. I'm not a journalist or
whistleblower or anything like that. I just think cryptography is
cool and privacy is important.
</p>
<p>
This is also a pretty easy one-off page for anyone to take and easily accept encrypted communications themselves.
You can see the source code for this tool on <a href="https://github.com/shreve/shreve.github.io/blob/master/encrypt.html">my GitHub</a>, or "view source" right here.
</p>
You can’t perform that action at this time.