-
Notifications
You must be signed in to change notification settings - Fork 17
/
libsodiumsealedcryptoboxencryptionsampledecryption.html
58 lines (56 loc) · 3.12 KB
/
libsodiumsealedcryptoboxencryptionsampledecryption.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Libsodium sealed crypto box hybrid string encryption (sample decryption only)</title>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
h2 {font-size: 200%;}
p {font-size: 150%; }
button {height: 100%; font-size: 150%;}
textarea {font-size: 150%;}
input[type="text"] {font-size: 100%; }
</style>
</head>
<body>
<h1>Libsodium sealed crypto box hybrid string encryption (sample decryption only)</h1>
<hr><p>
<b>Important note: this program is doing what it promises but the programming itself is of very poor quality and for demonstration purposes only. Never ever use this program as source for your own programs because there are a lot of conversions to get it run.</b>
<br><br>Get more information about this program on <a href="https://github.com/java-crypto/cross_platform_crypto/blob/main/docs/libsodium_sealedcryptobox_encryption_string.md" target="_blank">
my webpage <b>Libsodium sealed crypto box authenticated hybrid string encryption</b></a><br>
</p><hr>
<p><b>This is a sample version that shows how to decrypt data anonymized with fixed private key.</b></p><hr>
<h2>Decryption</h2>
<p>For decryption you need receipient's (party B) secret key.</p>
<p>Fixed (party B) Secret Key (in Base64 encoding):</p>
<textarea name="secretKeyBBase64" id="secretKeyBBase64" rows="2" cols="40" disabled>yNmXR5tfBXA/uZjanND+IYgGXlrFnrdUiUXesI4fOlM=</textarea>
<p>Insert the ciphertext you like to decrypt:</p>
<textarea name="ciphertextDecryptionBase64" id="ciphertextDecryptionBase64" rows="5" cols="40">wCnbPe8FkZJ9PVEh7eI90fY6IjkUWAZK5YLbGb3QdQbaxMqsP2KNpfM47LETnIJJDvE+QhFEjFYksnNSU8iLyfOKxtWtY/ZZvdrSQSPGsHXnUywQ+DArk8JeBg==</textarea><br>
<p>The input is (Base64) ciphertext</p>
<p>press the decrypt button to proceed:</p>
<button onclick="decryptSealed()">decrypt</button>
<p>decrypted plaintext:</p>
<textarea name="decryptedtext" id="decryptedtext" rows="6" cols="40">the decryptedtext comes here...</textarea>
<hr><p>
<b>Technical note: this program uses the X25519 key exchange algorithm, XSalsa20 stream cipher for encryption and Poly1305 MAC for authenticated encryption.</b>
</p><hr>
<script src="http://javacrypto.bplaced.net/cpclibsodium/nacl.min.js"></script>
<script src="http://javacrypto.bplaced.net/cpclibsodium/nacl-util.min.js"></script>
<script src="http://javacrypto.bplaced.net/cpclibsodium/sealedbox.web.js"></script>
<script>
function decryptSealed() {
var secretKeyBBase64 = document.getElementById('secretKeyBBase64').value;
var secretKeyB = nacl.util.decodeBase64(secretKeyBBase64);
// get the public key from secret key via generating the key pair
var keypair = nacl.box.keyPair.fromSecretKey(secretKeyB);
var publicKeyB = keypair.publicKey;
var ciphertext = nacl.util.decodeBase64(document.getElementById('ciphertextDecryptionBase64').value);
var decryptedtext = sealedBox.open(ciphertext, publicKeyB, secretKeyB);
document.getElementById('decryptedtext').value = nacl.util.encodeUTF8(decryptedtext);
}
</script>
</body>
</html>