Skip to content

Instantly share code, notes, and snippets.

@MKorostoff
Created December 19, 2016 19:13
Show Gist options
  • Save MKorostoff/d298ae98e2672926fabc6e1ffe0a981e to your computer and use it in GitHub Desktop.
Save MKorostoff/d298ae98e2672926fabc6e1ffe0a981e to your computer and use it in GitHub Desktop.
<!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.min.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...
var encrypt = new JSEncrypt();
encrypt.setPublicKey($('#pubkey').val());
var encrypted = encrypt.encrypt($('#input').val());
$('#output').val(encrypted);
});
});
</script>
</head>
<body>
<label for="pubkey">Public Key</label><br/>
<textarea id="pubkey" rows="15" cols="65">-----BEGIN PUBLIC KEY-----
MIG[REDACTED REDACTED REDACTED REDACTED REDACTED REDACTED ]DtO
R8ejVxToNb+D+mZFHfPhCV6/1r0ZNkuwsK6toSInmxVNISTn9AO0smTbfZpjJR/1
7+gg6kbagMu1tPM8pdj7RWtqih/1rG0fcIw1sCU34S6W9uj44b2mPFJU/lqDwxTi
4oGLsTaNwUoVhcuYVQIDAQAB
-----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="output">Encrypted Message</label><br/>
<textarea id="output" name="output" type="text" rows=4 cols=70></textarea><br/>
<input id="testme" type="button" value="Test Me!!!" /><br/>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment