-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsa.html
72 lines (64 loc) · 3.08 KB
/
rsa.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!--
PKCS1 - spec
openssl genrsa -out rsa_1024_priv.pem 1024
openssl rsa -pubout -in rsa_1024_priv.pem -out rsa_1024_pub.pem
-->
<!doctype html>
<html>
<head>
<title>JavaScript RSA Encryption</title>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="jsencrypt.js"></script>
<script type="text/javascript">
// Call this code when the page is done loading.
$(function () {
// Run a quick encryption/decryption when they click.
$('#testme').click(function () {
// Encrypt with the public key...
const encrypt = new JSEncrypt();
encrypt.setPublicKey($('#pubkey').val());
const encrypted = encrypt.encrypt($('#input').val());
$('#encrypted').val(encrypted);
// Decrypt with the private key...
const decrypt = new JSEncrypt();
decrypt.setPrivateKey($('#privkey').val());
const uncrypted = decrypt.decrypt(encrypted);
$('#decrypted').val(uncrypted);
});
});
</script>
</head>
<body>
<label for="privkey">Private Key</label>
<br/>
<textarea id="privkey" rows="15" cols="65">-----BEGIN RSA PRIVATE KEY----- MIICXgIBAAKBgQDauAAc1poFnLplzU1Ycnz6IFw5pLuEWTIvWQeXyQuHu2xcF4eo WONzqc+sHAcGJauov2g0h3k1I+Kpehx3OCV12m7DvJsPhOjVBlhfMiRDesYN9+HQ
1dzg6fbdHbndfJnLfEOSDwBKzvwbNBLid7Hb5yJekparxor9wZfj/vskGwIDAQAB AoGAXKTz50M/moD4s4Zy7LQSHCD477HHfBgMGeIsRS7zo1rQW3HcFIMSVTvoq45z
qzbpr2DkUtvPi6LXr9H5nMY7lxeEy8CRtkjGue7fDz7eUgwMwTsUOLZVFiel9Uuo AQsh9fcaFRMgD4EDN86SBtVAWGv2J273iU3rqUsl5kw3ZgECQQD1qswLkG2GE94A
8JddeQ4q7wQ2XcPcIbyjXBGqDzJK3OU9Q2dADvypFMmXDDKLjhNl6StGzAi4Ftg3 w+GYQFVrAkEA4+sJynGPTq8qwntsEs9Zg35iqBY8+si/rTAk2j03fF7mT2DZF1eu
V07RYCUIYrRBrYBvmNKHREOJOD1+noZoEQJBAKACdRB7K7sOqaS3D//j3yR7taSr geyZVMKaLy8y4rD8G5vBkTiaClsenQby/OEE0wGn03YzYuJ0jrQTs5Z1IK0CQQCX
1wUdzsvnYsF88ZbNbUA4XyHA05fqh4VTDwjuL+xgOiT7aw0WBP8MAWFxyRouD+LV gQRX7qHZM5keU7GgUPDRAkEAlzhNVTIT0Z8s7cJmS5aiSaVoWqS6q+gHATyV2Qwj
zT/z2apXn6C2ZRz7Fo1iPoJG7QDjyKnSNqXRVAPvcRxFXw== -----END RSA PRIVATE KEY-----
</textarea>
<br/>
<label for="pubkey">Public Key</label>
<br/>
<textarea id="pubkey" rows="15" cols="65">-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDauAAc1poFnLplzU1Ycnz6IFw5 pLuEWTIvWQeXyQuHu2xcF4eoWONzqc+sHAcGJauov2g0h3k1I+Kpehx3OCV12m7D
vJsPhOjVBlhfMiRDesYN9+HQ1dzg6fbdHbndfJnLfEOSDwBKzvwbNBLid7Hb5yJe kparxor9wZfj/vskGwIDAQAB -----END PUBLIC KEY-----
</textarea>
<br/>
<label for="input">Text to encrypt:</label>
<br/>
<textarea id="input" name="input" type="text" rows=4 cols=70>This is a test!</textarea>
<br>
<label for="input">Encrypted text:</label>
<br/>
<textarea id="encrypted" name="encrypted" type="text" rows=4 cols=70></textarea>
<br/>
<label for="input">Decrypted text:</label>
<br/>
<textarea id="decrypted" name="decrypted" type="text" rows=4 cols=70></textarea>
<br/>
<input id="testme" type="button" value="Test Me!!!" />
<br/>
</body>
</html>