Introduce unlock method for keys: passphrase is set as attribute of key and used

to decrypt required secret key packets on demand. Directly access config module in armor.js.
Key method getPrivateKeyPacket returns key packets by ID (optionally decrypted).
Message method decrypt returns new message with packetlist of decrypted message.
Add CRLF conversion to literal data packet. Packetlist: make filterByTag variadic,
add findPacket method. Keep state isDecrypted in secret key packet, don't decrypt
if already decrypted. Add mapToHex method to keyid. Simplify emailRegEx.
This commit is contained in:
Thomas Oberndörfer 2013-11-16 22:08:42 +01:00
parent 40701e09ab
commit c051eacf36
12 changed files with 764 additions and 555 deletions

File diff suppressed because one or more lines are too long

View File

@ -17,6 +17,7 @@
var base64 = require('./base64.js');
var enums = require('../enums.js');
var config = require('../config');
/**
* Finds out which Ascii Armoring type is used. This is an internal function
@ -79,13 +80,13 @@ function get_type(text) {
* @version 2011-12-16
* @returns {String} The header information
*/
function armor_addheader(options) {
function armor_addheader() {
var result = "";
if (options.show_version) {
result += "Version: " + options.versionstring + '\r\n';
if (config.show_version) {
result += "Version: " + config.versionstring + '\r\n';
}
if (options.show_comment) {
result += "Comment: " + options.commentstring + '\r\n';
if (config.show_comment) {
result += "Comment: " + config.commentstring + '\r\n';
}
result += '\r\n';
return result;
@ -234,7 +235,7 @@ function dearmor(text) {
text: splittedtext[2]
.replace(/\n- /g, "\n")
.split("\n\n")[1],
openpgp: base64_decode(splittedtext[4]
openpgp: base64.decode(splittedtext[4]
.split("\n\n")[1]
.split("\n=")[0]),
type: type
@ -261,19 +262,19 @@ function dearmor(text) {
* @param {Integer} parttotal
* @returns {String} Armored text
*/
function armor(messagetype, data, options, partindex, parttotal) {
function armor(messagetype, data, partindex, parttotal) {
var result = "";
switch (messagetype) {
case enums.armor.multipart_section:
result += "-----BEGIN PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n";
result += armor_addheader(options);
result += armor_addheader();
result += base64.encode(data);
result += "\r\n=" + getCheckSum(data) + "\r\n";
result += "-----END PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n";
break;
case enums.armor.mutlipart_last:
result += "-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n";
result += armor_addheader(options);
result += armor_addheader();
result += base64.encode(data);
result += "\r\n=" + getCheckSum(data) + "\r\n";
result += "-----END PGP MESSAGE, PART " + partindex + "-----\r\n";
@ -282,28 +283,28 @@ function armor(messagetype, data, options, partindex, parttotal) {
result += "\r\n-----BEGIN PGP SIGNED MESSAGE-----\r\nHash: " + data.hash + "\r\n\r\n";
result += data.text.replace(/\n-/g, "\n- -");
result += "\r\n-----BEGIN PGP SIGNATURE-----\r\n";
result += armor_addheader(options);
result += armor_addheader();
result += base64.encode(data.openpgp);
result += "\r\n=" + getCheckSum(data.openpgp) + "\r\n";
result += "-----END PGP SIGNATURE-----\r\n";
break;
case enums.armor.message:
result += "-----BEGIN PGP MESSAGE-----\r\n";
result += armor_addheader(options);
result += armor_addheader();
result += base64.encode(data);
result += "\r\n=" + getCheckSum(data) + "\r\n";
result += "-----END PGP MESSAGE-----\r\n";
break;
case enums.armor.public_key:
result += "-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n";
result += armor_addheader(options);
result += armor_addheader();
result += base64.encode(data);
result += "\r\n=" + getCheckSum(data) + "\r\n";
result += "-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n";
break;
case enums.armor.private_key:
result += "-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n";
result += armor_addheader(options);
result += armor_addheader();
result += base64.encode(data);
result += "\r\n=" + getCheckSum(data) + "\r\n";
result += "-----END PGP PRIVATE KEY BLOCK-----\r\n";

View File

@ -32,6 +32,7 @@ var config = require('./config');
this.packets = packetlist || new packet.list();
this.passphrase = null;
/**
* Returns the primary key packet (secret or public)
@ -86,22 +87,12 @@ var config = require('./config');
return keyIds;
}
/**
* Returns key IDs of all key packets in hex
* @returns {[String]}
*/
this.getKeyIdsHex = function() {
return this.getKeyIds().map(function(keyId) {
return keyId.toHex();
});
}
/**
* Returns first key packet which match to an array of key IDs
* Returns first key packet for given array of key IDs
* @param {[keyid]} keyIds
* @return {public_subkey|secret_subkey|packet_secret_key|packet_public_key|null}
*/
this.getKeyPacketByIds = function(keyIds) {
this.getKeyPacket = function(keyIds) {
var keys = this.getAllKeyPackets();
for (var i = 0; i < keys.length; i++) {
var keyId = keys[i].getKeyId();
@ -115,13 +106,37 @@ var config = require('./config');
return null;
}
/**
* Returns first private key packet for given array of key IDs
* @param {[keyid]} keyIds
* @param {Boolean} decrypted decrypt private key packet
* @return {secret_subkey|packet_secret_key|null}
*/
this.getPrivateKeyPacket = function(keyIds, decrypted) {
var keys = this.packets.filterByTag(enums.packet.secret_key, enums.packet.secret_subkey);
for (var i = 0; i < keys.length; i++) {
var keyId = keys[i].getKeyId();
for (var j = 0; j < keyIds.length; j++) {
if (keyId.equals(keyIds[j])) {
//TODO return only verified keys
if (decrypted) {
if (!this.passphrase) throw new Error('No passphrase to decrypt key.');
keys[i].decrypt(this.passphrase);
}
return keys[i];
}
}
}
return null;
}
/**
* Returns true if this is a public key
* @return {Boolean}
*/
this.isPublic = function() {
var publicKeyPackets = this.packets.filterByTag(enums.packet.public_key);
return publicKeyPackets.length !== 0 ? true : false;
return publicKeyPackets.length ? true : false;
}
/**
@ -130,7 +145,7 @@ var config = require('./config');
*/
this.isPrivate = function() {
var privateKeyPackets = this.packets.filterByTag(enums.packet.private_key);
return privateKeyPackets.length !== 0 ? true : false;
return privateKeyPackets.length ? true : false;
}
/**
@ -202,16 +217,25 @@ var config = require('./config');
* @return {undefined}
*/
this.decrypt = function(passphrase) {
//TODO boolean return value
//TODO return value
var keys = this.getAllKeyPackets();
for (var i in keys)
for (var i in keys) {
if (keys[i].tag == enums.packet.secret_subkey ||
keys[i].tag == enums.packet.secret_key) {
keys[i].decrypt(passphrase);
if (!passphrase && !this.passphrase) throw new Error('No passphrase to decrypt key.');
keys[i].decrypt(passphrase || this.passphrase);
}
}
}
/**
* Unlocks the key with passphrase, decryption of secret keys deferred. This allows to decrypt the required private key packets on demand
* @param {String} passphrase
* @return {undefined}
*/
this.unlock = function(passphrase) {
this.passphrase = passphrase;
}
// TODO
this.verify = function() {

View File

@ -18,6 +18,8 @@
var packet = require('./packet');
var enums = require('./enums.js');
var armor = require('./encoding/armor.js');
var config = require('./config');
var crypto = require('./crypto');
/**
* @class
@ -32,9 +34,9 @@ function message(packetlist) {
* Returns the key IDs of the public keys to which the session key is encrypted
* @return {[keyId]} array of keyid objects
*/
this.getKeyIds = function() {
this.getEncryptionKeyIds = function() {
var keyIds = [];
var pkESKeyPacketlist = this.packets.filterByType(enums.packet.public_key_encrypted_session_key);
var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.public_key_encrypted_session_key);
pkESKeyPacketlist.forEach(function(packet) {
keyIds.push(packet.publicKeyId);
});
@ -42,51 +44,78 @@ function message(packetlist) {
}
/**
* Returns the key IDs in hex of the public keys to which the session key is encrypted
* @return {[String]} keyId provided as string of hex numbers (lowercase)
* Decrypt the message
* @param {key} privateKey unlocked private key for which the message is encrypted (corresponding to the session key)
* @return {[message]} new message with decrypted content
*/
this.getKeyIdsHex = function() {
return this.getKeyIds().map(function(keyId) {
return keyId.toHex();
});
}
/**
* Decrypts the message
* @param {secret_subkey|packet_secret_key} privateKeyPacket the private key packet (with decrypted secret part) the message is encrypted with (corresponding to the session key)
* @return {[String]} array with plaintext of decrypted messages
*/
this.decrypt = function(privateKeyPacket) {
var decryptedMessages = [];
var pkESKeyPacketlist = this.packets.filterByType(enums.packet.public_key_encrypted_session_key);
this.decrypt = function(privateKey) {
var encryptionKeyIds = this.getEncryptionKeyIds();
if (!encryptionKeyIds.length) {
// nothing to decrypt return unmodified message
return this;
}
var privateKeyPacket = privateKey.getPrivateKeyPacket(encryptionKeyIds, true);
var pkESKeyPacketlist = this.packets.filterByTag(enums.packet.public_key_encrypted_session_key);
var pkESKeyPacket;
for (var i = 0; i < pkESKeyPacketlist.length; i++) {
var pkESKeyPacket = pkESKeyPacketlist[i];
if (pkESKeyPacket.publicKeyId.equals(privateKeyPacket.getKeyId())) {
if (pkESKeyPacketlist[i].publicKeyId.equals(privateKeyPacket.getKeyId())) {
pkESKeyPacket = pkESKeyPacketlist[i];
pkESKeyPacket.decrypt(privateKeyPacket);
var symEncryptedPacketlist = this.packets.filter(function(packet) {
return packet.tag == enums.packet.symmetrically_encrypted || packet.tag == enums.packet.sym_encrypted_integrity_protected;
});
for (var k = 0; k < symEncryptedPacketlist.length; k++) {
var symEncryptedPacket = symEncryptedPacketlist[k];
symEncryptedPacket.decrypt(pkESKeyPacket.sessionKeyAlgorithm, pkESKeyPacket.sessionKey);
for (var l = 0; l < symEncryptedPacket.packets.length; l++) {
var dataPacket = symEncryptedPacket.packets[l];
switch (dataPacket.tag) {
case enums.packet.literal:
decryptedMessages.push(dataPacket.getBytes());
break;
case enums.packet.compressed:
//TODO
break;
default:
//TODO
}
}
}
break;
}
}
return decryptedMessages;
if (pkESKeyPacket) {
var symEncryptedPacketlist = this.packets.filterByTag(enums.packet.symmetrically_encrypted, enums.packet.sym_encrypted_integrity_protected);
if (symEncryptedPacketlist.length !== 0) {
var symEncryptedPacket = symEncryptedPacketlist[0];
symEncryptedPacket.decrypt(pkESKeyPacket.sessionKeyAlgorithm, pkESKeyPacket.sessionKey);
return new message(symEncryptedPacket.packets);
}
}
}
/**
* Get literal data that is the body of the message
* @return {String|null} literal body of the message as string
*/
this.getLiteral = function() {
var literal = this.packets.findPacket(enums.packet.literal);
return literal && literal.data || null;
}
/**
* Encrypt the message
* @param {[key]} keys array of keys, used to encrypt the message
* @return {[message]} new message with encrypted content
*/
this.encrypt = function(keys) {
var packetlist = new packet.list();
//TODO get preferred algo from signature
var sessionKey = crypto.generateSessionKey(enums.read(enums.symmetric, config.encryption_cipher));
keys.forEach(function(key) {
var encryptionKeyPacket = key.getEncryptionKeyPacket();
if (encryptionKeyPacket) {
var pkESKeyPacket = new packet.public_key_encrypted_session_key();
pkESKeyPacket.publicKeyId = encryptionKeyPacket.getKeyId();
pkESKeyPacket.publicKeyAlgorithm = encryptionKeyPacket.algorithm;
pkESKeyPacket.sessionKey = sessionKey;
//TODO get preferred algo from signature
pkESKeyPacket.sessionKeyAlgorithm = enums.read(enums.symmetric, config.encryption_cipher);
pkESKeyPacket.encrypt(encryptionKeyPacket);
packetlist.push(pkESKeyPacket);
}
});
var symEncryptedPacket;
if (config.integrity_protect) {
symEncryptedPacket = new packet.sym_encrypted_integrity_protected();
} else {
symEncryptedPacket = new packet.symmetrically_encrypted();
}
symEncryptedPacket.packets = this.packets;
//TODO get preferred algo from signature
symEncryptedPacket.encrypt(enums.read(enums.symmetric, config.encryption_cipher), sessionKey);
packetlist.push(symEncryptedPacket);
return new message(packetlist);
}
/**
@ -170,7 +199,7 @@ function message(packetlist) {
/**
* reads an OpenPGP armored message and returns a message object
* @param {String} armoredText text to be parsed
* @return {key} new message object
* @return {message} new message object
*/
message.readArmored = function(armoredText) {
//TODO how do we want to handle bad text? Exception throwing
@ -182,4 +211,19 @@ message.readArmored = function(armoredText) {
return newMessage;
}
/**
* creates new message object from text
* @param {String} text
* @return {message} new message object
*/
message.fromText = function(text) {
var literalDataPacket = new packet.literal();
// text will be converted to UTF8
literalDataPacket.set(text);
var literalDataPacketlist = new packet.list();
literalDataPacketlist.push(literalDataPacket);
var newMessage = new message(literalDataPacketlist);
return newMessage;
}
module.exports = message;

View File

@ -25,8 +25,8 @@ var armor = require('./encoding/armor.js');
var packet = require('./packet');
var util = require('./util');
var enums = require('./enums.js');
var crypto = require('./crypto');
var config = require('./config');
var message = require('./message.js');
/**
* GPG4Browsers Core interface. A single instance is hold
@ -36,52 +36,17 @@ var config = require('./config');
* @classdesc Main Openpgp.js class. Use this to initiate and make all calls to this library.
*/
function _openpgp() {
this.tostring = "";
/**
* encrypts message with keys
* @param {[key]} keys array of keys, used to encrypt the message
* @param {String} message text message as native JavaScript string
* @param {String} text message as native JavaScript string
* @return {String} encrypted ASCII armored message
*/
function encryptMessage(keys, message) {
var messagePacketlist = new packet.list();
//TODO get preferred algo from signature
var sessionKey = crypto.generateSessionKey(enums.read(enums.symmetric, config.encryption_cipher));
keys.forEach(function(key) {
var encryptionKeyPacket = key.getEncryptionKeyPacket();
if (encryptionKeyPacket) {
var pkESKeyPacket = new packet.public_key_encrypted_session_key();
pkESKeyPacket.publicKeyId = encryptionKeyPacket.getKeyId();
pkESKeyPacket.publicKeyAlgorithm = encryptionKeyPacket.algorithm;
pkESKeyPacket.sessionKey = sessionKey;
//TODO get preferred algo from signature
pkESKeyPacket.sessionKeyAlgorithm = enums.read(enums.symmetric, config.encryption_cipher);
pkESKeyPacket.encrypt(encryptionKeyPacket);
messagePacketlist.push(pkESKeyPacket);
}
});
var literalDataPacket = new packet.literal();
literalDataPacket.set(message, 'utf8');
var literalDataPacketlist = new packet.list();
literalDataPacketlist.push(literalDataPacket);
var symEncryptedPacket;
if (config.integrity_protect) {
symEncryptedPacket = new packet.sym_encrypted_integrity_protected();
} else {
symEncryptedPacket = new packet.symmetrically_encrypted();
}
symEncryptedPacket.packets = literalDataPacketlist;
//TODO get preferred algo from signature
symEncryptedPacket.encrypt(enums.read(enums.symmetric, config.encryption_cipher), sessionKey);
messagePacketlist.push(symEncryptedPacket);
var armored = armor.encode(enums.armor.message, messagePacketlist.write(), config);
function encryptMessage(keys, text) {
var msg = message.fromText(text);
msg = msg.encrypt(keys);
var armored = armor.encode(enums.armor.message, msg.packets.write());
return armored;
}
@ -91,12 +56,14 @@ function _openpgp() {
/**
* decrypts message
* @param {secret_subkey|packet_secret_key} privateKeyPacket the private key packet (with decrypted secret part) the message is encrypted with
* @param {key} privateKey unlocked private key
* @param {message} message the message object with the encrypted data
* @return {String} decrypted message as as native JavaScript string
* @return {String|null} decrypted message as as native JavaScript string
* or null if no literal data found
*/
function decryptMessage(privateKeyPacket, message) {
return message.decrypt(privateKeyPacket);
function decryptMessage(privateKey, message) {
message = message.decrypt(privateKey);
return message.getLiteral();
}
function decryptAndVerifyMessage(privateKey, publicKeys, messagePacketlist) {
@ -169,7 +136,7 @@ function _openpgp() {
packetlist.push(secretSubkeyPacket);
packetlist.push(subkeySignaturePacket);
var armored = armor.encode(enums.armor.private_key, packetlist.write(), this.config);
var armored = armor.encode(enums.armor.private_key, packetlist.write());
return armored;
}

View File

@ -26,35 +26,40 @@ var util = require('../util'),
* is not to be further interpreted.
*/
module.exports = function packet_literal() {
this.format = 'utf8';
this.data = '';
this.format = 'utf8'; // default format for literal data packets
this.data = ''; // literal data representation as native JavaScript string or bytes
this.date = new Date();
/**
* Set the packet data to a javascript native string or a squence of
* bytes. Conversion to a proper utf8 encoding takes place when the
* bytes. Conversion to the provided format takes place when the
* packet is written.
* @param {String} str Any native javascript string
* @param {openpgp_packet_literaldata.format} format
* @param {'utf8|'binary'|'text'} format The format the packet data will be written to,
* defaults to 'utf8'
*/
this.set = function(str, format) {
this.format = format;
this.format = format || this.format;
this.data = str;
}
/**
* Set the packet data to value represented by the provided string
* of bytes together with the appropriate conversion format.
* Set the packet data to value represented by the provided string of bytes.
* @param {String} bytes The string of bytes
* @param {openpgp_packet_literaldata.format} format
* @param {'utf8|'binary'|'text'} format The format of the string of bytes
*/
this.setBytes = function(bytes, format) {
this.format = format;
if (format == 'utf8')
bytes = util.decode_utf8(bytes);
switch (format) {
case 'utf8':
bytes = util.decode_utf8(bytes);
bytes = bytes.replace(/\r\n/g, '\n');
break;
case 'text':
bytes = bytes.replace(/\r\n/g, '\n');
break;
}
this.data = bytes;
}
@ -63,10 +68,17 @@ module.exports = function packet_literal() {
* @returns {String} A sequence of bytes
*/
this.getBytes = function() {
if (this.format == 'utf8')
return util.encode_utf8(this.data);
else
return this.data;
var bytes = this.data;
switch (this.format) {
case 'utf8':
bytes = bytes.replace(/\n/g, '\r\n');
bytes = util.encode_utf8(bytes);
break;
case 'text':
bytes = bytes.replace(/\n/g, '\r\n');
break;
}
return bytes;
}

View File

@ -62,10 +62,10 @@ module.exports = function packetlist() {
this.length++;
}
/**
* Creates a new packetList with all packets that pass the test implemented by the provided function.
*/
this.filter = function(callback) {
/**
* Creates a new packetList with all packets that pass the test implemented by the provided function.
*/
this.filter = function(callback) {
var filtered = new packetlist();
@ -75,25 +75,54 @@ module.exports = function packetlist() {
}
}
return filtered;
}
return filtered;
}
/**
* Creates a new packetList with all packets from the given type
*/
this.filterByType = function(packetType) {
return this.filter(function(packet) {
return packet.tag == packetType;
});
}
/**
* Creates a new packetList with all packets from the given types
*/
this.filterByTag = function() {
var args = Array.prototype.slice.call(arguments);
var filtered = new packetlist();
var that = this;
/**
* Executes the provided callback once for each element
*/
this.forEach = function(callback) {
for (var i = 0; i < this.length; i++) {
for (var i = 0; i < this.length; i++) {
if (args.some(function(packetType) {return that[i].tag == packetType})) {
filtered.push(this[i]);
}
}
return filtered;
}
/**
* Executes the provided callback once for each element
*/
this.forEach = function(callback) {
for (var i = 0; i < this.length; i++) {
callback(this[i]);
}
}
}
/**
* Traverses packet tree and returns first matching packet
* @param {enums.packet} type The packet type
* @return {[type]}
*/
this.findPacket = function(type) {
var packetlist = this.filterByTag(type);
if (packetlist.length) {
return packetlist[0];
} else {
var found = null;
for (var i = 0; i < this.length; i++) {
if (this[i].packets.length) {
found = this[i].packets.findPacket(type);
if (found) return found;
}
}
}
return null;
}
}

View File

@ -33,8 +33,10 @@ var publicKey = require('./public_key.js'),
*/
function packet_secret_key() {
publicKey.call(this);
// encrypted secret-key data
this.encrypted = null;
// indicator if secret-key data is available in decrypted form
this.isDecrypted = false;
function get_hash_len(hash) {
@ -127,6 +129,7 @@ function packet_secret_key() {
this.mpi = this.mpi.concat(parse_cleartext_mpi('mod', bytes.substr(1),
this.algorithm));
this.isDecrypted = true;
}
};
@ -200,7 +203,7 @@ function packet_secret_key() {
* @return {Boolean} True if the passphrase was correct; false if not
*/
this.decrypt = function(passphrase) {
if (!this.encrypted)
if (this.isDecrypted)
return;
var i = 0,
@ -249,10 +252,12 @@ function packet_secret_key() {
this.mpi = this.mpi.concat(parse_cleartext_mpi(hash, cleartext,
this.algorithm));
this.isDecrypted = true;
};
this.generate = function(bits, passphrase) {
this.mpi = crypto.generateMpi(this.algorithm, bits);
this.isDecrypted = true;
};
}

View File

@ -25,7 +25,7 @@ var util = require('../util');
section "Enhanced Key Formats" below describes how Key IDs are
formed.
*/
module.exports = function keyid() {
function keyid() {
// initialize keyid with 0x0000000000000000
var strArray = [];
@ -58,4 +58,10 @@ module.exports = function keyid() {
this.equals = function(keyid) {
return this.bytes == keyid.bytes;
}
};
}
keyid.mapToHex = function(keyid) {
return keyid.toHex();
}
module.exports = keyid;

View File

@ -52,8 +52,7 @@ var Util = function() {
return this.writeNumber(numeric, 4);
};
this.emailRegEx =
/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
this.emailRegEx = /^[+a-zA-Z0-9_.-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,6}$/;
this.debug = false;

View File

@ -11,31 +11,21 @@ unit.register("Key generation/encryption/decryption", function() {
+ 'userid: ' + userid + '\n'
+ 'message: ' + message;
debugger;
var privKey = openpgp.key.readArmored(key);
var encrypted = openpgp.encryptMessage([privKey], message);
var msg = openpgp.message.readArmored(encrypted);
// Find the private (sub)key for the session key of the message
var privKeyPacket = privKey.getKeyPacketByIds(msg.getKeyIds());
if (!privKeyPacket) {
return new unit.result("No private key found!" + info, false);
}
privKey.unlock(passphrase);
try {
if (!privKeyPacket.decrypt(passphrase)) {
return new unit.result("Password for secrect key was incorrect!" + info, false);
}
var decrypted = openpgp.decryptMessage(privKey, msg);
return new unit.result(message + ' == ' + decrypted + info, message == decrypted);
} catch (e) {
return new unit.result("Exception on decrypt of private key packet!" + info, false);
}
var decrypted = msg.decrypt(privKeyPacket)[0];
return new unit.result(message + ' == ' + decrypted + info, message == decrypted);
};
result.push(testHelper('password', 'Test McTestington <test@example.com>', 'hello world'));
@ -117,21 +107,7 @@ unit.register("Encryption/decryption", function() {
'=lw5e',
'-----END PGP PRIVATE KEY BLOCK-----'].join('\n');
var armored =
['-----BEGIN PGP MESSAGE-----',
'Version: OpenPGP.js VERSION',
'Comment: http://openpgpjs.org',
'',
'wYwD4IT3RGwgLJcBA/wN8H9qUvsJwsarDOcsczk1L9Iif47jy+3vF6LcpSgA',
'DfKSARWvatyakvEJmuCNfcpzS8NUPnFA51p0VWmI7FnYG5LkPVUIHb4sN07G',
'9PeqhaayZIeNVvS6DoYuxiTG2sbDmyrv6MMSLivs7VcTAN6L7XXJRI2IumOS',
'x2WFgYNKANJFAQmen4R4IGf9nZDI7NJ4QHUlK1GENgLix9RzMK+Cri6p9Gx5',
'4MDV23jgCBWrUHfFYximgcXiUk0NfpVD3x6chcnKUKJv',
'=Eaix',
'-----END PGP MESSAGE-----'].join('\n');
var plaintext = 'short message';
var plaintext = 'short message\nnext line\n한국어/조선말';
var key = openpgp.key.readArmored(pub_key);
@ -141,11 +117,9 @@ unit.register("Encryption/decryption", function() {
var privKey = openpgp.key.readArmored(priv_key);
var privKeyPacket = privKey.getKeyPacketByIds(message.getKeyIds());
privKey.unlock('hello world');
privKeyPacket.decrypt('hello world');
var decrypted = openpgp.decryptMessage(privKeyPacket, message);
var decrypted = openpgp.decryptMessage(privKey, message);
result[0] = new unit.result('Encrypt plain text and afterwards decrypt leads to same result', plaintext == decrypted);

File diff suppressed because one or more lines are too long