Included CRC-24 Lookup table. Changes to keyring so importing return booleans, allow for password import of private key.
This commit is contained in:
parent
e4915a2fcd
commit
13b52ebd51
|
@ -10918,21 +10918,42 @@ function verifyCheckSum(data, checksum) {
|
|||
* @param data [String] data to create a CRC-24 checksum for
|
||||
* @return [Integer] the CRC-24 checksum as number
|
||||
*/
|
||||
function createcrc24 (data) {
|
||||
var crc = 0xB704CE;
|
||||
var i;
|
||||
var mypos = 0;
|
||||
var len = data.length;
|
||||
while (len--) {
|
||||
crc ^= (data[mypos++].charCodeAt()) << 16;
|
||||
for (i = 0; i < 8; i++) {
|
||||
crc <<= 1;
|
||||
if (crc & 0x1000000)
|
||||
crc ^= 0x1864CFB;
|
||||
}
|
||||
}
|
||||
return crc & 0xFFFFFF;
|
||||
var crc_table = [
|
||||
0x00000000, 0x00864cfb, 0x018ad50d, 0x010c99f6, 0x0393e6e1, 0x0315aa1a, 0x021933ec, 0x029f7f17, 0x07a18139, 0x0727cdc2, 0x062b5434, 0x06ad18cf, 0x043267d8, 0x04b42b23, 0x05b8b2d5, 0x053efe2e, 0x0fc54e89, 0x0f430272, 0x0e4f9b84, 0x0ec9d77f, 0x0c56a868, 0x0cd0e493, 0x0ddc7d65, 0x0d5a319e, 0x0864cfb0, 0x08e2834b, 0x09ee1abd, 0x09685646, 0x0bf72951, 0x0b7165aa, 0x0a7dfc5c, 0x0afbb0a7, 0x1f0cd1e9, 0x1f8a9d12, 0x1e8604e4, 0x1e00481f, 0x1c9f3708, 0x1c197bf3, 0x1d15e205, 0x1d93aefe, 0x18ad50d0, 0x182b1c2b, 0x192785dd, 0x19a1c926, 0x1b3eb631, 0x1bb8faca, 0x1ab4633c, 0x1a322fc7, 0x10c99f60, 0x104fd39b, 0x11434a6d, 0x11c50696, 0x135a7981, 0x13dc357a, 0x12d0ac8c, 0x1256e077, 0x17681e59, 0x17ee52a2, 0x16e2cb54, 0x166487af, 0x14fbf8b8, 0x147db443, 0x15712db5, 0x15f7614e, 0x3e19a3d2, 0x3e9fef29, 0x3f9376df, 0x3f153a24, 0x3d8a4533, 0x3d0c09c8, 0x3c00903e, 0x3c86dcc5, 0x39b822eb, 0x393e6e10, 0x3832f7e6, 0x38b4bb1d, 0x3a2bc40a, 0x3aad88f1, 0x3ba11107, 0x3b275dfc, 0x31dced5b, 0x315aa1a0,
|
||||
0x30563856, 0x30d074ad, 0x324f0bba, 0x32c94741, 0x33c5deb7, 0x3343924c, 0x367d6c62, 0x36fb2099, 0x37f7b96f, 0x3771f594, 0x35ee8a83, 0x3568c678, 0x34645f8e, 0x34e21375, 0x2115723b, 0x21933ec0, 0x209fa736, 0x2019ebcd, 0x228694da, 0x2200d821, 0x230c41d7, 0x238a0d2c, 0x26b4f302, 0x2632bff9, 0x273e260f, 0x27b86af4, 0x252715e3, 0x25a15918, 0x24adc0ee, 0x242b8c15, 0x2ed03cb2, 0x2e567049, 0x2f5ae9bf, 0x2fdca544, 0x2d43da53, 0x2dc596a8, 0x2cc90f5e, 0x2c4f43a5, 0x2971bd8b, 0x29f7f170, 0x28fb6886, 0x287d247d, 0x2ae25b6a, 0x2a641791, 0x2b688e67, 0x2beec29c, 0x7c3347a4, 0x7cb50b5f, 0x7db992a9, 0x7d3fde52, 0x7fa0a145, 0x7f26edbe, 0x7e2a7448, 0x7eac38b3, 0x7b92c69d, 0x7b148a66, 0x7a181390, 0x7a9e5f6b, 0x7801207c, 0x78876c87, 0x798bf571, 0x790db98a, 0x73f6092d, 0x737045d6, 0x727cdc20, 0x72fa90db, 0x7065efcc, 0x70e3a337, 0x71ef3ac1, 0x7169763a, 0x74578814, 0x74d1c4ef, 0x75dd5d19, 0x755b11e2, 0x77c46ef5, 0x7742220e, 0x764ebbf8, 0x76c8f703, 0x633f964d, 0x63b9dab6, 0x62b54340, 0x62330fbb,
|
||||
0x60ac70ac, 0x602a3c57, 0x6126a5a1, 0x61a0e95a, 0x649e1774, 0x64185b8f, 0x6514c279, 0x65928e82, 0x670df195, 0x678bbd6e, 0x66872498, 0x66016863, 0x6cfad8c4, 0x6c7c943f, 0x6d700dc9, 0x6df64132, 0x6f693e25, 0x6fef72de, 0x6ee3eb28, 0x6e65a7d3, 0x6b5b59fd, 0x6bdd1506, 0x6ad18cf0, 0x6a57c00b, 0x68c8bf1c, 0x684ef3e7, 0x69426a11, 0x69c426ea, 0x422ae476, 0x42aca88d, 0x43a0317b, 0x43267d80, 0x41b90297, 0x413f4e6c, 0x4033d79a, 0x40b59b61, 0x458b654f, 0x450d29b4, 0x4401b042, 0x4487fcb9, 0x461883ae, 0x469ecf55, 0x479256a3, 0x47141a58, 0x4defaaff, 0x4d69e604, 0x4c657ff2, 0x4ce33309, 0x4e7c4c1e, 0x4efa00e5, 0x4ff69913, 0x4f70d5e8, 0x4a4e2bc6, 0x4ac8673d, 0x4bc4fecb, 0x4b42b230, 0x49ddcd27, 0x495b81dc, 0x4857182a, 0x48d154d1, 0x5d26359f, 0x5da07964, 0x5cace092, 0x5c2aac69, 0x5eb5d37e, 0x5e339f85, 0x5f3f0673, 0x5fb94a88, 0x5a87b4a6, 0x5a01f85d, 0x5b0d61ab, 0x5b8b2d50, 0x59145247, 0x59921ebc, 0x589e874a, 0x5818cbb1, 0x52e37b16, 0x526537ed, 0x5369ae1b, 0x53efe2e0, 0x51709df7, 0x51f6d10c,
|
||||
0x50fa48fa, 0x507c0401, 0x5542fa2f, 0x55c4b6d4, 0x54c82f22, 0x544e63d9, 0x56d11cce, 0x56575035, 0x575bc9c3, 0x57dd8538];
|
||||
|
||||
function createcrc24(input) {
|
||||
var crc = 0xB704CE;
|
||||
var index = 0;
|
||||
|
||||
while((input.length - index) > 16) {
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+1)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+2)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+3)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+4)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+5)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+6)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+7)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+8)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+9)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+10)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+11)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+12)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+13)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+14)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+15)) & 0xff];
|
||||
index += 16;
|
||||
}
|
||||
|
||||
for(var j = index; j < input.length; j++) {
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index++)) & 0xff]
|
||||
}
|
||||
return crc & 0xffffff;
|
||||
}
|
||||
|
||||
// GPG4Browsers - An OpenPGP implementation in javascript
|
||||
// Copyright (C) 2011 Recurity Labs GmbH
|
||||
//
|
||||
|
@ -11522,6 +11543,7 @@ function openpgp_keyring() {
|
|||
for (var i = 0; i < result.length; i++) {
|
||||
this.publicKeys[this.publicKeys.length] = {armored: armored_text, obj: result[i], keyId: result[i].getKeyId()};
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11529,11 +11551,14 @@ function openpgp_keyring() {
|
|||
* @param armored_text [String] PRIVATE KEY BLOCK message to read the private key from
|
||||
* @return [null] nothing
|
||||
*/
|
||||
function importPrivateKey (armored_text) {
|
||||
function importPrivateKey (armored_text, password) {
|
||||
var result = openpgp.read_privateKey(armored_text);
|
||||
if(!result[0].decryptSecretMPIs(password))
|
||||
return false;
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
this.privateKeys[this.privateKeys.length] = {armored: armored_text, obj: result[i], keyId: result[i].getKeyId()};
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
this.importPublicKey = importPublicKey;
|
||||
|
|
14
resources/openpgp.min.js
vendored
14
resources/openpgp.min.js
vendored
|
@ -408,7 +408,15 @@ function openpgp_encoding_armor_addheader(){var a="";openpgp.config.config.show_
|
|||
function openpgp_encoding_armor(a,b,c,d){var e="";switch(a){case 0:e=e+("-----BEGIN PGP MESSAGE, PART "+c+"/"+d+"-----\r\n")+openpgp_encoding_armor_addheader();e+=openpgp_encoding_base64_encode(b);e+="\r\n="+getCheckSum(b)+"\r\n";e+="-----END PGP MESSAGE, PART "+c+"/"+d+"-----\r\n";break;case 1:e=e+("-----BEGIN PGP MESSAGE, PART "+c+"-----\r\n")+openpgp_encoding_armor_addheader();e+=openpgp_encoding_base64_encode(b);e+="\r\n="+getCheckSum(b)+"\r\n";e+="-----END PGP MESSAGE, PART "+c+"-----\r\n";break;
|
||||
case 2:e+="\r\n-----BEGIN PGP SIGNED MESSAGE-----\r\nHash: "+b.hash+"\r\n\r\n";e+=b.text.replace(/\n-/g,"\n- -");e=e+"\r\n-----BEGIN PGP SIGNATURE-----\r\n"+openpgp_encoding_armor_addheader();e+=openpgp_encoding_base64_encode(b.openpgp);e+="\r\n="+getCheckSum(b.openpgp)+"\r\n";e+="-----END PGP SIGNATURE-----\r\n";break;case 3:e=e+"-----BEGIN PGP MESSAGE-----\r\n"+openpgp_encoding_armor_addheader();e+=openpgp_encoding_base64_encode(b);e+="\r\n="+getCheckSum(b)+"\r\n";e+="-----END PGP MESSAGE-----\r\n";
|
||||
break;case 4:e=e+"-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n"+openpgp_encoding_armor_addheader();e+=openpgp_encoding_base64_encode(b);e+="\r\n="+getCheckSum(b)+"\r\n";e+="-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n";break;case 5:e=e+"-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n"+openpgp_encoding_armor_addheader(),e+=openpgp_encoding_base64_encode(b),e+="\r\n="+getCheckSum(b)+"\r\n",e+="-----END PGP PRIVATE KEY BLOCK-----\r\n"}return e}
|
||||
function getCheckSum(a){a=createcrc24(a);a=""+String.fromCharCode(a>>16)+String.fromCharCode(a>>8&255)+String.fromCharCode(a&255);return openpgp_encoding_base64_encode(a)}function verifyCheckSum(a,b){var c=getCheckSum(a);return c[0]==b[0]&&c[1]==b[1]&&c[2]==b[2]}function createcrc24(a){for(var b=11994318,c,d=0,e=a.length;e--;){b^=a[d++].charCodeAt()<<16;for(c=0;8>c;c++)b<<=1,b&16777216&&(b^=25578747)}return b&16777215}
|
||||
function getCheckSum(a){a=createcrc24(a);a=""+String.fromCharCode(a>>16)+String.fromCharCode(a>>8&255)+String.fromCharCode(a&255);return openpgp_encoding_base64_encode(a)}function verifyCheckSum(a,b){var c=getCheckSum(a);return c[0]==b[0]&&c[1]==b[1]&&c[2]==b[2]}
|
||||
var crc_table=[0,8801531,25875725,17603062,60024545,51751450,35206124,44007191,128024889,120049090,103502900,112007375,70412248,78916387,95990485,88014382,264588937,256049778,240098180,248108927,207005800,215016595,232553829,224014750,140824496,149062475,166599357,157832774,200747345,191980970,176028764,184266919,520933865,529177874,512099556,503334943,480196360,471432179,487973381,496217854,414011600,405478443,422020573,430033190,457094705,465107658,448029500,439496647,281648992,273666971,289622637,
|
||||
298124950,324696449,333198714,315665548,307683447,392699481,401494690,383961940,375687087,352057528,343782467,359738805,368533838,1041867730,1050668841,1066628831,1058355748,1032471859,1024199112,1006669886,1015471301,968368875,960392720,942864358,951368477,975946762,984451313,1000411399,992435708,836562267,828023200,810956886,818967725,844041146,852051777,868605623,860066380,914189410,922427545,938981743,930215316,904825475,896059E3,878993294,887231349,555053627,563297984,547333942,538569677,579245274,
|
||||
570480673,588005847,596249900,649392898,640860153,658384399,666397428,623318499,631331096,615366894,606833685,785398962,777416777,794487231,802989380,759421523,767923880,751374174,743392165,695319947,704115056,687564934,679289981,719477610,711202705,728272487,737067676,2083735460,2092239711,2109313705,2101337682,2141233477,2133257662,2116711496,2125215923,2073216669,2064943718,2048398224,2057199467,2013339772,2022141063,2039215473,2030942602,1945504045,1936737750,1920785440,1929023707,1885728716,
|
||||
1893966647,1911503553,1902736954,1951893524,1959904495,1977441561,1968902626,2009362165,2000822798,1984871416,1992881923,1665111629,1673124534,1656046400,1647513531,1621913772,1613380695,1629922721,1637935450,1688082292,1679317903,1695859321,1704103554,1728967061,1737211246,1720132760,1711368291,1828378820,1820103743,1836060105,1844855090,1869168165,1877963486,1860430632,1852155859,1801148925,1809650950,1792118E3,1784135691,1757986588,1750004711,1765960209,1774462698,1110107254,1118611597,1134571899,
|
||||
1126595968,1102643863,1094667884,1077139354,1085643617,1166763343,1158490548,1140961346,1149762745,1176011694,1184812885,1200772771,1192499800,1307552511,1298785796,1281720306,1289958153,1316768798,1325007077,1341561107,1332794856,1246636998,1254647613,1271201483,1262662192,1239272743,1230733788,1213667370,1221678289,1562785183,1570797924,1554833554,1546300521,1588974462,1580441477,1597965939,1605978760,1518843046,1510078557,1527603627,1535847760,1494504007,1502748348,1486784330,1478020017,1390639894,
|
||||
1382365165,1399434779,1408230112,1366334967,1375129868,1358579962,1350304769,1430452783,1438955220,1422405410,1414423513,1456544974,1448562741,1465633219,1474135352];
|
||||
function createcrc24(a){for(var b=11994318,c=0;16<a.length-c;)b=b<<8^crc_table[(b>>16^a.charCodeAt(c))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+1))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+2))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+3))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+4))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+5))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+6))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+7))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+8))&255],b=b<<8^crc_table[(b>>
|
||||
16^a.charCodeAt(c+9))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+10))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+11))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+12))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+13))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+14))&255],b=b<<8^crc_table[(b>>16^a.charCodeAt(c+15))&255],c+=16;for(var d=c;d<a.length;d++)b=b<<8^crc_table[(b>>16^a.charCodeAt(c++))&255];return b&16777215}
|
||||
function openpgp_msg_message(){this.text="";this.decrypt=function(a,b){if(null==a||null==b||""==b)return null;var c=b.decrypt(this,a.keymaterial);if(null==c)return null;var d,e=0,f=c.length;for(util.print_debug("openpgp.msg.messge decrypt:\n"+util.hexstrdump(c));e!=c.length&&null!=(d=openpgp_packet.read_packet(c,e,f));){if(8==d.tagType)this.text=d.decompress(),c=d.decompress();util.print_debug(d.toString());e+=d.headerLength+d.packetLength;38<e&&util.print_debug("openpgp.msg.messge decrypt:\n"+util.hexstrdump(c.substring(e)));
|
||||
f=c.length-e;if(11==d.tagType)this.text=d.data,util.print_info("message successfully decrypted");if(19!=d.tagType&&2==d.tagType&&3>d.signatureType){var g=openpgp.keyring.getPublicKeysForKeyId(d.issuerKeyId);0==g.length?util.print_warning("Unable to verify signature of issuer: "+util.hexstrdump(d.issuerKeyId)+". Public key not found in keyring."):d.verify(this.text.replace(/\r\n/g,"\n").replace(/\n/g,"\r\n"),g[0])&&g[0].obj.validate()?util.print_info("Found Good Signature from "+g[0].obj.userIds[0].text+
|
||||
" (0x"+util.hexstrdump(g[0].obj.getKeyId()).substring(8)+")"):util.print_error("Signature verification failed: Bad Signature from "+g[0].obj.userIds[0].text+" (0x"+util.hexstrdump(g[0].obj.getKeyId()).substring(8)+")")}}if(""==this.text)this.text=c;return this.text};this.verifySignature=function(){var a=!1;if(2==this.type){var b;if(4==this.signature.version)b=openpgp.keyring.getPublicKeysForKeyId(this.signature.issuerKeyId);else if(3==this.signature.version)b=openpgp.keyring.getPublicKeysForKeyId(this.signature.keyId);
|
||||
|
@ -424,8 +432,8 @@ function openpgp_keyring(){this.init=function(){var a=JSON.parse(window.localSto
|
|||
obj:e[0],keyId:e[0].getKeyId()},c++)};this.hasPrivateKey=function(){return 0<this.privateKeys.length};this.store=function(){for(var a=[],b=0;b<this.privateKeys.length;b++)a[b]=this.privateKeys[b].armored;for(var c=[],b=0;b<this.publicKeys.length;b++)c[b]=this.publicKeys[b].armored;window.localStorage.setItem("privatekeys",JSON.stringify(a));window.localStorage.setItem("publickeys",JSON.stringify(c))};this.getPublicKeyForAddress=function(a){for(var b=[],c=a.split("<"),d="",d=1<c.length?c[1].split(">")[0]:
|
||||
a.trim(),a=0;a<this.publicKeys.length;a++)for(c=0;c<this.publicKeys[a].obj.userIds.length;c++)0<=this.publicKeys[a].obj.userIds[c].text.indexOf(d)&&(b[b.length]=this.publicKeys[a]);return b};this.getPrivateKeyForAddress=function(a){for(var b=[],c=a.split("<"),d="",d=1<c.length?c[1].split(">")[0]:a.trim(),a=0;a<this.privateKeys.length;a++)for(c=0;c<this.privateKeys[a].obj.userIds.length;c++)0<=this.privateKeys[a].obj.userIds[c].text.indexOf(d)&&(b[b.length]=this.privateKeys[a]);return b};this.getPublicKeysForKeyId=
|
||||
function(a){for(var b=[],c=0;c<this.publicKeys.length;c++)a==this.publicKeys[c].obj.getKeyId()&&(b[b.length]=this.publicKeys[c]);return b};this.getPrivateKeyForKeyId=function(a){for(var b=[],c=0;c<this.privateKeys.length;c++)if(a==util.hexstrdump(this.privateKeys[c].obj.getKeyId())&&(b[b.length]={key:this.privateKeys[c],keymaterial:this.privateKeys[c].obj.privateKeyPacket}),null!=this.privateKeys[c].obj.subKeys)for(var d=this.privateKeys[c].obj.getSubKeyIds(),e=0;e<d.length;e++)a==util.hexstrdump(d[e])&&
|
||||
(b[b.length]={key:this.privateKeys[c],keymaterial:this.privateKeys[c].obj.subKeys[e]});return b};this.importPublicKey=function(a){for(var b=openpgp.read_publicKey(a),c=0;c<b.length;c++)this.publicKeys[this.publicKeys.length]={armored:a,obj:b[c],keyId:b[c].getKeyId()}};this.importPrivateKey=function(a){for(var b=openpgp.read_privateKey(a),c=0;c<b.length;c++)this.privateKeys[this.privateKeys.length]={armored:a,obj:b[c],keyId:b[c].getKeyId()}};this.exportPublicKey=function(a){return this.publicKey[a]};
|
||||
this.removePublicKey=function(a){a=this.publicKeys.splice(a,1);this.store();return a};this.exportPrivateKey=function(a){return this.privateKeys[a]};this.removePrivateKey=function(a){a=this.privateKeys.splice(a,1);this.store();return a}}
|
||||
(b[b.length]={key:this.privateKeys[c],keymaterial:this.privateKeys[c].obj.subKeys[e]});return b};this.importPublicKey=function(a){for(var b=openpgp.read_publicKey(a),c=0;c<b.length;c++)this.publicKeys[this.publicKeys.length]={armored:a,obj:b[c],keyId:b[c].getKeyId()};return!0};this.importPrivateKey=function(a,b){var c=openpgp.read_privateKey(a);if(!c[0].decryptSecretMPIs(b))return!1;for(var d=0;d<c.length;d++)this.privateKeys[this.privateKeys.length]={armored:a,obj:c[d],keyId:c[d].getKeyId()};return!0};
|
||||
this.exportPublicKey=function(a){return this.publicKey[a]};this.removePublicKey=function(a){a=this.publicKeys.splice(a,1);this.store();return a};this.exportPrivateKey=function(a){return this.privateKeys[a]};this.removePrivateKey=function(a){a=this.privateKeys.splice(a,1);this.store();return a}}
|
||||
var Util=function(){this.hexdump=function(a){for(var b=[],c=a.length,d=0,e,f=0;d<c;){for(e=a.charCodeAt(d++).toString(16);2>e.length;)e="0"+e;b.push(" "+e);f++;0==f%32&&b.push("\n ")}return b.join("")};this.hexstrdump=function(a){if(null==a)return"";for(var b=[],c=a.length,d=0,e;d<c;){for(e=a[d++].charCodeAt().toString(16);2>e.length;)e="0"+e;b.push(""+e)}return b.join("")};this.hexidump=function(a){for(var b=[],c=a.length,d=0,e;d<c;){for(e=a[d++].toString(16);2>e.length;)e="0"+e;b.push(""+
|
||||
e)}return b.join("")};this.str2bin=function(a){for(var b=[],c=0;c<a.length;c++)b[c]=a.charCodeAt(c);return b};this.bin2str=function(a){for(var b=[],c=0;c<a.length;c++)b.push(String.fromCharCode(a[c]));return b.join("")};this.calc_checksum=function(a){for(var b={s:0,add:function(a){this.s=(this.s+a)%65536}},c=0;c<a.length;c++)b.add(a.charCodeAt(c));return b.s};this.print_debug=function(a){openpgp.config.debug&&(a=openpgp_encoding_html_encode(a),showMessages('<tt><p style="background-color: #ffffff; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;">'+
|
||||
a.replace(/\n/g,"<br>")+"</p></tt>"))};this.print_debug_hexstr_dump=function(a,b){openpgp.config.debug&&(a+=this.hexstrdump(b),a=openpgp_encoding_html_encode(a),showMessages('<tt><p style="background-color: #ffffff; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;">'+a.replace(/\n/g,"<br>")+"</p></tt>"))};this.print_error=function(a){a=openpgp_encoding_html_encode(a);showMessages('<p style="font-size: 80%; background-color: #FF8888; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;"><span style="color: #888;"><b>ERROR:</b></span>\t'+
|
||||
|
|
|
@ -205,18 +205,39 @@ function verifyCheckSum(data, checksum) {
|
|||
* @param data [String] data to create a CRC-24 checksum for
|
||||
* @return [Integer] the CRC-24 checksum as number
|
||||
*/
|
||||
function createcrc24 (data) {
|
||||
var crc = 0xB704CE;
|
||||
var i;
|
||||
var mypos = 0;
|
||||
var len = data.length;
|
||||
while (len--) {
|
||||
crc ^= (data[mypos++].charCodeAt()) << 16;
|
||||
for (i = 0; i < 8; i++) {
|
||||
crc <<= 1;
|
||||
if (crc & 0x1000000)
|
||||
crc ^= 0x1864CFB;
|
||||
}
|
||||
}
|
||||
return crc & 0xFFFFFF;
|
||||
var crc_table = [
|
||||
0x00000000, 0x00864cfb, 0x018ad50d, 0x010c99f6, 0x0393e6e1, 0x0315aa1a, 0x021933ec, 0x029f7f17, 0x07a18139, 0x0727cdc2, 0x062b5434, 0x06ad18cf, 0x043267d8, 0x04b42b23, 0x05b8b2d5, 0x053efe2e, 0x0fc54e89, 0x0f430272, 0x0e4f9b84, 0x0ec9d77f, 0x0c56a868, 0x0cd0e493, 0x0ddc7d65, 0x0d5a319e, 0x0864cfb0, 0x08e2834b, 0x09ee1abd, 0x09685646, 0x0bf72951, 0x0b7165aa, 0x0a7dfc5c, 0x0afbb0a7, 0x1f0cd1e9, 0x1f8a9d12, 0x1e8604e4, 0x1e00481f, 0x1c9f3708, 0x1c197bf3, 0x1d15e205, 0x1d93aefe, 0x18ad50d0, 0x182b1c2b, 0x192785dd, 0x19a1c926, 0x1b3eb631, 0x1bb8faca, 0x1ab4633c, 0x1a322fc7, 0x10c99f60, 0x104fd39b, 0x11434a6d, 0x11c50696, 0x135a7981, 0x13dc357a, 0x12d0ac8c, 0x1256e077, 0x17681e59, 0x17ee52a2, 0x16e2cb54, 0x166487af, 0x14fbf8b8, 0x147db443, 0x15712db5, 0x15f7614e, 0x3e19a3d2, 0x3e9fef29, 0x3f9376df, 0x3f153a24, 0x3d8a4533, 0x3d0c09c8, 0x3c00903e, 0x3c86dcc5, 0x39b822eb, 0x393e6e10, 0x3832f7e6, 0x38b4bb1d, 0x3a2bc40a, 0x3aad88f1, 0x3ba11107, 0x3b275dfc, 0x31dced5b, 0x315aa1a0,
|
||||
0x30563856, 0x30d074ad, 0x324f0bba, 0x32c94741, 0x33c5deb7, 0x3343924c, 0x367d6c62, 0x36fb2099, 0x37f7b96f, 0x3771f594, 0x35ee8a83, 0x3568c678, 0x34645f8e, 0x34e21375, 0x2115723b, 0x21933ec0, 0x209fa736, 0x2019ebcd, 0x228694da, 0x2200d821, 0x230c41d7, 0x238a0d2c, 0x26b4f302, 0x2632bff9, 0x273e260f, 0x27b86af4, 0x252715e3, 0x25a15918, 0x24adc0ee, 0x242b8c15, 0x2ed03cb2, 0x2e567049, 0x2f5ae9bf, 0x2fdca544, 0x2d43da53, 0x2dc596a8, 0x2cc90f5e, 0x2c4f43a5, 0x2971bd8b, 0x29f7f170, 0x28fb6886, 0x287d247d, 0x2ae25b6a, 0x2a641791, 0x2b688e67, 0x2beec29c, 0x7c3347a4, 0x7cb50b5f, 0x7db992a9, 0x7d3fde52, 0x7fa0a145, 0x7f26edbe, 0x7e2a7448, 0x7eac38b3, 0x7b92c69d, 0x7b148a66, 0x7a181390, 0x7a9e5f6b, 0x7801207c, 0x78876c87, 0x798bf571, 0x790db98a, 0x73f6092d, 0x737045d6, 0x727cdc20, 0x72fa90db, 0x7065efcc, 0x70e3a337, 0x71ef3ac1, 0x7169763a, 0x74578814, 0x74d1c4ef, 0x75dd5d19, 0x755b11e2, 0x77c46ef5, 0x7742220e, 0x764ebbf8, 0x76c8f703, 0x633f964d, 0x63b9dab6, 0x62b54340, 0x62330fbb,
|
||||
0x60ac70ac, 0x602a3c57, 0x6126a5a1, 0x61a0e95a, 0x649e1774, 0x64185b8f, 0x6514c279, 0x65928e82, 0x670df195, 0x678bbd6e, 0x66872498, 0x66016863, 0x6cfad8c4, 0x6c7c943f, 0x6d700dc9, 0x6df64132, 0x6f693e25, 0x6fef72de, 0x6ee3eb28, 0x6e65a7d3, 0x6b5b59fd, 0x6bdd1506, 0x6ad18cf0, 0x6a57c00b, 0x68c8bf1c, 0x684ef3e7, 0x69426a11, 0x69c426ea, 0x422ae476, 0x42aca88d, 0x43a0317b, 0x43267d80, 0x41b90297, 0x413f4e6c, 0x4033d79a, 0x40b59b61, 0x458b654f, 0x450d29b4, 0x4401b042, 0x4487fcb9, 0x461883ae, 0x469ecf55, 0x479256a3, 0x47141a58, 0x4defaaff, 0x4d69e604, 0x4c657ff2, 0x4ce33309, 0x4e7c4c1e, 0x4efa00e5, 0x4ff69913, 0x4f70d5e8, 0x4a4e2bc6, 0x4ac8673d, 0x4bc4fecb, 0x4b42b230, 0x49ddcd27, 0x495b81dc, 0x4857182a, 0x48d154d1, 0x5d26359f, 0x5da07964, 0x5cace092, 0x5c2aac69, 0x5eb5d37e, 0x5e339f85, 0x5f3f0673, 0x5fb94a88, 0x5a87b4a6, 0x5a01f85d, 0x5b0d61ab, 0x5b8b2d50, 0x59145247, 0x59921ebc, 0x589e874a, 0x5818cbb1, 0x52e37b16, 0x526537ed, 0x5369ae1b, 0x53efe2e0, 0x51709df7, 0x51f6d10c,
|
||||
0x50fa48fa, 0x507c0401, 0x5542fa2f, 0x55c4b6d4, 0x54c82f22, 0x544e63d9, 0x56d11cce, 0x56575035, 0x575bc9c3, 0x57dd8538];
|
||||
|
||||
function createcrc24(input) {
|
||||
var crc = 0xB704CE;
|
||||
var index = 0;
|
||||
|
||||
while((input.length - index) > 16) {
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+1)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+2)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+3)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+4)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+5)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+6)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+7)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+8)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+9)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+10)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+11)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+12)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+13)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+14)) & 0xff];
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index+15)) & 0xff];
|
||||
index += 16;
|
||||
}
|
||||
|
||||
for(var j = index; j < input.length; j++) {
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 16) ^ input.charCodeAt(index++)) & 0xff]
|
||||
}
|
||||
return crc & 0xffffff;
|
||||
}
|
||||
|
||||
|
|
|
@ -176,6 +176,7 @@ function openpgp_keyring() {
|
|||
for (var i = 0; i < result.length; i++) {
|
||||
this.publicKeys[this.publicKeys.length] = {armored: armored_text, obj: result[i], keyId: result[i].getKeyId()};
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -183,11 +184,14 @@ function openpgp_keyring() {
|
|||
* @param armored_text [String] PRIVATE KEY BLOCK message to read the private key from
|
||||
* @return [null] nothing
|
||||
*/
|
||||
function importPrivateKey (armored_text) {
|
||||
function importPrivateKey (armored_text, password) {
|
||||
var result = openpgp.read_privateKey(armored_text);
|
||||
if(!result[0].decryptSecretMPIs(password))
|
||||
return false;
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
this.privateKeys[this.privateKeys.length] = {armored: armored_text, obj: result[i], keyId: result[i].getKeyId()};
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
this.importPublicKey = importPublicKey;
|
||||
|
|
Loading…
Reference in New Issue
Block a user