- added encryption.html for testing encrytion / decryption of messages
This commit is contained in:
parent
f486f601af
commit
377dd12d19
|
@ -178,7 +178,7 @@ function openpgp_packet_encryptedsessionkey() {
|
|||
key.secMPIs, this.MPIs).toMPI();
|
||||
var checksum = ((result.charCodeAt(result.length - 2) << 8) + result
|
||||
.charCodeAt(result.length - 1));
|
||||
var decoded = openpgp_encoding_eme_pkcs1_decode(result.substring(2, result.length - 2));
|
||||
var decoded = openpgp_encoding_eme_pkcs1_decode(result.substring(2, result.length - 2), key.publicKey.MPIs[0].getByteLength());
|
||||
var sesskey = decoded.substring(1);
|
||||
var algo = decoded.charCodeAt(0);
|
||||
if (msg.encryptedData.tagType == 18)
|
||||
|
|
206
test/encryption.html
Normal file
206
test/encryption.html
Normal file
|
@ -0,0 +1,206 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<script type="text/javascript" src="../resources/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/hash/sha.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/hash/md5.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/hash/ripe-md.js"></script>
|
||||
|
||||
<!-- crypto libs -->
|
||||
<script type="text/javascript" src="../src/ciphers/symmetric/aes.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/symmetric/cast5.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/symmetric/dessrc.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/symmetric/twofish.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/symmetric/blowfish.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../src/ciphers/asymmetric/jsbn.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/asymmetric/jsbn2.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/asymmetric/dsa.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/asymmetric/elgamal.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/asymmetric/rsa.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../src/ciphers/openpgp.crypto.js"></script>
|
||||
<script type="text/javascript" src="../src/ciphers/openpgp.cfb.js"></script>
|
||||
|
||||
<!-- compression -->
|
||||
|
||||
<!-- encoding -->
|
||||
<script type="text/javascript" src="../src/encoding/base64.js"></script>
|
||||
<script type="text/javascript" src="../src/encoding/openpgp.encoding.asciiarmor.js"></script>
|
||||
<script type="text/javascript" src="../src/encoding/openpgp.encoding.js"></script>
|
||||
|
||||
<!-- openpgp types -->
|
||||
<script type="text/javascript" src="../src/type/openpgp.type.keyid.js"></script>
|
||||
<script type="text/javascript" src="../src/type/openpgp.type.mpi.js"></script>
|
||||
<script type="text/javascript" src="../src/type/openpgp.type.s2k.js"></script>
|
||||
|
||||
<!-- openpgp packets -->
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.compressed.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.encrypteddata.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.encryptedintegrityprotecteddata.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.encryptedsessionkey.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.keymaterial.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.literaldata.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.marker.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.modificationdetectioncode.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.onepasssignature.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.signature.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.userattribute.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.userid.js"></script>
|
||||
<script type="text/javascript" src="../src/packet/openpgp.packet.js"></script>
|
||||
|
||||
<!-- openpgp impl. -->
|
||||
<script type="text/javascript" src="../src/openpgp.js"></script>
|
||||
<script type="text/javascript" src="../src/config/openpgp.config.js"></script>
|
||||
<script type="text/javascript" src="../src/openpgp.keyring.js"></script>
|
||||
<script type="text/javascript" src="../src/openpgp.msg.message.js"></script>
|
||||
<script type="text/javascript" src="../src/openpgp.msg.privatekey.js"></script>
|
||||
<script type="text/javascript" src="../src/openpgp.msg.publickey.js"></script>
|
||||
<script type="text/javascript" src="../src/util/util.js"></script>
|
||||
|
||||
<!-- unit test -->
|
||||
<script type="text/javascript" src="unittest.js"></script>
|
||||
<script type="text/javascript" src="example-test.js"></script>
|
||||
<title>OpenPGP.js testpage</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<style>
|
||||
* {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
#debug, #testoutput {
|
||||
border: 1px dotted #aaa;
|
||||
background-color: #eee;
|
||||
margin: 5px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
openpgp.init();
|
||||
|
||||
// message function required by util.print_message, util.print_debug, util.print_warning
|
||||
|
||||
function showMessages(str) {
|
||||
$('#debug').append(str);
|
||||
}
|
||||
|
||||
function run(encrypt) {
|
||||
if (encrypt && $('#signmessage').is(':checked')) {
|
||||
var priv_key = openpgp.read_privateKey($('#privatekeysignature').val());
|
||||
var pub_key = openpgp.read_publicKey($('#publickeyinput').val());
|
||||
if (priv_key.length < 1) {
|
||||
util.print_error("No private key found!")
|
||||
return;
|
||||
}
|
||||
if (pub_key < 1) {
|
||||
util.print_error("No public key found!")
|
||||
return;
|
||||
}
|
||||
if (!priv_key[0].decryptSecretMPIs($('#encpassword').val())) {
|
||||
util.print_error("Password for secrect key was incorrect!");
|
||||
return;
|
||||
}
|
||||
$('#messageoutput').text(openpgp.write_signed_and_encrypted_message(priv_key[0],pub_key,$('#messageinput').val()));
|
||||
} else if (encrypt) {
|
||||
var pub_key = openpgp.read_publicKey($('#publickeyinput').val());
|
||||
if (pub_key < 1) {
|
||||
util.print_error("No public key found!")
|
||||
return;
|
||||
}
|
||||
$('#messageoutput').text(openpgp.write_encrypted_message(pub_key,$('#messageinput').val()));
|
||||
} else {
|
||||
if ($('#verifysignature').is(':checked')) {
|
||||
var pub_key = openpgp.read_publicKey($('#publickeysignature').val());
|
||||
if (pub_key == null)
|
||||
util.print_error("Unable to read public key");
|
||||
openpgp.keyring.importPublicKey($('#publickeysignature').val());
|
||||
}
|
||||
|
||||
var priv_key = openpgp.read_privateKey($('#privatekeyinput').val());
|
||||
|
||||
if (priv_key.length < 1) {
|
||||
util.print_error("No private key found!")
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = openpgp.read_message($('#messageinput').val());
|
||||
var keymat = null;
|
||||
var sesskey = null;
|
||||
// Find the private (sub)key for the session key of the message
|
||||
for (var i = 0; i< msg[0].sessionKeys.length; i++) {
|
||||
if (priv_key[0].privateKeyPacket.publicKey.getKeyId() == msg[0].sessionKeys[i].keyId.bytes) {
|
||||
keymat = { key: priv_key[0], keymaterial: priv_key[0].privateKeyPacket};
|
||||
sesskey = msg[0].sessionKeys[i];
|
||||
break;
|
||||
}
|
||||
for (var j = 0; j < priv_key[0].subKeys.length; j++) {
|
||||
if (priv_key[0].subKeys[j].publicKey.getKeyId() == msg[0].sessionKeys[i].keyId.bytes) {
|
||||
keymat = { key: priv_key[0], keymaterial: priv_key[0].subKeys[j]};
|
||||
sesskey = msg[0].sessionKeys[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (keymat != null) {
|
||||
if (!keymat.keymaterial.decryptSecretMPIs($('#decpassword').val())) {
|
||||
util.print_error("Password for secrect key was incorrect!");
|
||||
return;
|
||||
|
||||
}
|
||||
$('#messageoutput').text(msg[0].decrypt(keymat, sesskey));
|
||||
} else {
|
||||
util.print_error("No private key found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function showMessages(str) {
|
||||
$('#debug').append(str);
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#enabledebug').is(':checked') ? openpgp.config.debug = true : openpgp.config.debug = false;
|
||||
});
|
||||
</script>
|
||||
<a href="index.html">Unit Tests</a> | <a href="parser.html">Parser</a> | <a href="encryption.html">Encryption / Decryption</a>
|
||||
<p><input id="enabledebug" type="checkbox" onclick="($('#enabledebug').is(':checked') ? openpgp.config.debug = true : openpgp.config.debug = false)"> Print Debug Messages </p>
|
||||
<h1>Encrypt / Decrypt Messages</h1>
|
||||
<input type="radio" name="direction" value="0" checked="checked" onmousedown="$('#decrypt').hide(); $('#encrypt').show();">Encrypt Message |
|
||||
<input type="radio" name="direction" value="1" onmousedown="$('#encrypt').hide(); $('#decrypt').show();">Decrypt Message
|
||||
<h2>Message</h2>
|
||||
<textarea id="messageinput" cols="80" rows="25"></textarea>
|
||||
<div id="encrypt" style="display: block">
|
||||
<h2 id="keytitle">Public Key Block</h2>
|
||||
<textarea id="publickeyinput" cols="80" rows="25"></textarea><br>
|
||||
Sign message: <input type="checkbox" id="signmessage" onchange="$('#signature').toggle();"><br>
|
||||
<div id="signature" style="display: none">
|
||||
<h3>Private Key for Signing the Message:</h3>
|
||||
<textarea id="privatekeysignature" cols="80" rows="25"></textarea><br>
|
||||
Password for private key: <input type="password" id="encpassword">
|
||||
</div>
|
||||
<button type="submit" onmousedown="run(true)">Encrypt</button>
|
||||
</div>
|
||||
<div id="decrypt" style="display: none">
|
||||
<h2 id="keytitle">Private Key Block</h2>
|
||||
<textarea id="privatekeyinput" cols="80" rows="25"></textarea><br>
|
||||
Password for private key: <input type="text" id="decpassword"><br>
|
||||
Verify Signature: <input type="checkbox" id="verifysignature" onchange="$('#verification').toggle();">
|
||||
<div id="verification" style="display: none">
|
||||
<h3>Public Key for Signature Verification:</h3>
|
||||
<textarea id="publickeysignature" cols="80" rows="25"></textarea><br>
|
||||
</div>
|
||||
<button type="submit" onmousedown="run(false)">Decrypt</button>
|
||||
</div>
|
||||
<h2>Result</h2>
|
||||
<pre id="messageoutput"></pre>
|
||||
|
||||
<!-- src/util/util.js print_debug() writes to -->
|
||||
<h2>Messages</h2>
|
||||
<div id="debug"></div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user