Please note I'm using 2 different functions getKeyId()
and getKeyIds().........

calling getKeyIds() on either the public or private Key gives me 2 keys (in
array) ( pubKey.getKeyIds()[0].toHex(); +' '+pubKey.getKeyIds()[1].toHex()
) - the first key [0] is the PublicKeyId.

calling getKeyId() -  pubKey.primaryKey.getKeyId().toHex() on the public or
private key EQUALS  pubKey.getKeyIds()[0].toHex() - which is the PublicKeyId

If I run this on encrypted message:
pgpmessage = openpgp.message.readArmored(pgpmessage);
pgpmessage.packets[0]['publicKeyId'].toHex()

it returns the same key as pubKey.getKeyIds()[1].toHex() does on public or
private key.

Am I correct in assuming this ( pubKey.getKeyIds()[1].toHex() ) is the
subKeyId ? it is the only common identifier that is the same in public key,
private key or encrypted message.

I've tried this on numerous openpgp keys and encrypted messages with the
same result.

What I find hard to understand is why
pgpmessage.packets[0]['publicKeyId'].toHex() returns this key as packets[0]
clearly shows this as ]['publicKeyId'].
when in fact it's not the PublicKeyId, could it be the subKeyId ??





On Thu, Dec 17, 2015 at 5:14 PM, Andrew <[email protected]> wrote:

> I'm getting the publicKeyId from the Public Key with this function:
> which ties with the signature correctly.
> function findkeyid(){
> var openpgp = window.openpgp;
> var testPublicKey = sessionStorage.getItem('testPublicKey');
> var foundKeys = openpgp.key.readArmored(testPublicKey).keys;
> if (!foundKeys || foundKeys.length !== 1) {
>    throw new Error("Key not readed, or more than one key");
> }
> var pubKey = foundKeys[0]; foundKeys = null;
> var getKeyId = function (key) {
>  return key.primaryKey.getKeyId().toHex();
> }
> console.log('publicKeyId '+getKeyId(pubKey));
> }
>
> I'm a bit confused by your "PGP key" what is that?
>
> I was hoping that I could extract the publicKeyId from the message and use
> that to determine what public Key was used to encrypt the message - this
> assumes I have several public keys etc.
>
> On Thu, Dec 17, 2015 at 4:39 PM, Tio Oscar <[email protected]> wrote:
>
>> By other hand, 6F9AE3EF7B6DB9C8 is the keyId of the public key, not the
>> PGP key, it's "F2F3C0463B4D9830", you need to obtain the keyId from
>> key.primaryKey.
>>
>>
>>
>> El jue., 17 de dic. de 2015 a la(s) 20:29, Tio Oscar <[email protected]>
>> escribió:
>>
>>> There is not wrong, the key fingerprint isn't the keyId, the keyID are
>>> the las 8 octets of the fingerprint.
>>>
>>> 3.3 <https://tools.ietf.org/html/rfc4880#section-3.3>.  Key IDs
>>>
>>>    A Key ID is an eight-octet scalar that identifies a key.
>>>    Implementations SHOULD NOT assume that Key IDs are unique.  The
>>>    section "Enhanced Key Formats" below describes how Key IDs are
>>>    formed.
>>>
>>>
>>>
>>> https://tools.ietf.org/html/rfc4880#section-3.3
>>>
>>> In hex, how is represented, are 16 chars (2 char by octet), the keyId
>>> are correct.
>>>
>>> El jue., 17 de dic. de 2015 a la(s) 19:43, Andrew <[email protected]>
>>> escribió:
>>>
>>>> Hi Tio,
>>>>
>>>> -----BEGIN PGP PUBLIC KEY BLOCK-----
>>>> Version: OpenPGP.js v1.3.0
>>>> Comment: http://openpgpjs.org
>>>>
>>>> xsBNBFZwoBwBCADbTO4n8WRnG1ktQUZLJYgsC4cVy70BHyotHl6wpAGLirpb
>>>> HZ2erWLk5u4B5hdNTR3ZF5YLgE9EymgUh42BRt4786MuXplHLw/JplGpCL6t
>>>> 9eXSzlSlUrbQ6oOTt18vA8fCvEy7guXw+G3ez/f2GfLgOGi2dCgNWUAuY8Zy
>>>> vRpHAnrdhXd8btAOHba15XD9fxUqw+vbf7a9V+vj2/bTBhlEUCbfozcUl/qs
>>>> 2F3PG3CZnuoznMoJuqHcTnL3vs6DCxBjyi6DnLVL6yHeJ7rCLf5agK6ZTfXs
>>>> WOOik5X6ZJgROnRYrm7GodbHlQH//5Kir3uG+7rCILGEzZTU3adbm5rrABEB
>>>> AAHNEjxhZzU3NDNAZ21haWwuY29tPsLAcgQQAQgAJgUCVnCgIQYLCQgHAwIJ
>>>> EPLzwEY7TZgwBBUIAgoDFgIBAhsDAh4BAAAuzwgAibMW3hEGR5c+3VhhJ3S2
>>>> 7lF7XKjFKyduEt5AoYjONEpO3YQZtJNal3lMnQqyFSn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9zxOp1
>>>> rwjp1g7s9qqQRhVzoMAtQgzeenkIgmZkQyd6Ba12UmNiszhRPP0=
>>>> =wLZD
>>>> -----END PGP PUBLIC KEY BLOCK-----
>>>>
>>>>
>>>> my public key signature is: 04f4d2ee95856f1d3e48aebcf2f3c0463b4d9830
>>>>
>>>> using console.log(pgpMessage.packets[0].publicKeyId.toHex()  ); I
>>>> get: 6f9ae3ef7b6db9c8
>>>>
>>>> the message:
>>>>
>>>> -----BEGIN PGP MESSAGE-----
>>>> Version: OpenPGP.js v1.3.0
>>>> Comment: http://openpgpjs.org
>>>>
>>>> wcBMA2+a4+97bbnIAQf/aHclrmHwOXdRIhiM32zjiC+8dM+IXZPfRAJXHfbr
>>>> TeTtO5bxBIP83Hv+Ytk5mL89TYWvhgpcG0YxV8rBtb4xSipK6N26cG6vpF1V
>>>> YngsjKLZ4niW0TvP9fy9bkkYjXMd+RdQq2t27X9xbMUSHTzGsl9EKYy1P3ZW
>>>> YxuB2Zpqm0tzQTU6eMkdbA3tAaw3JbUfUK1OyDBEeSO5X3MPFH4ftaxcWFUV
>>>> pysv7xm4IErSjMlhHu602ShQpg6HZe6768pbe4xWC4fZcSZQ/tlVNpyPLw0O
>>>> /WsBRe9KHKmfEfiuY+wRF9f0Ky73zeEEm0rUKA+KB2ycpjUYtzXDZrP/jLtX
>>>> 1dJMAe5ymyUNG7heZHaRvcB7mc4yMyNKMgrN6rAmPqDgMx8RFe7imq/wQ3yS
>>>> 0feZoTDximM69wWz71IQfpBza+NJJIj52WQI01Go/jU7HQ==
>>>> =rIyN
>>>> -----END PGP MESSAGE-----
>>>>
>>>> any idea why the keyId is wrong?
>>>>
>>>> On Thu, Dec 17, 2015 at 3:01 PM, Tio Oscar <[email protected]> wrote:
>>>>
>>>>> There is not docunented, but there are a method called toHex:
>>>>>
>>>>>
>>>>> Keyid.prototype.toHex = function() {  return 
>>>>> util.hexstrdump(this.bytes);};
>>>>>
>>>>> In your case:
>>>>>
>>>>> console.log(pgpMessage.packets[0].publicKeyId.toHex()  );
>>>>>
>>>>> El jue., 17 de dic. de 2015 a la(s) 18:03, Andrew <[email protected]>
>>>>> escribió:
>>>>>
>>>>>> I am trying to get the publicKeyId from the encrypted message.
>>>>>>
>>>>>> pgpMessage = openpgp.message.readArmored(pgpMessage);
>>>>>>
>>>>>> console.log( JSON.stringify( pgpMessage ) )
>>>>>> returns:
>>>>>>
>>>>>>
>>>>>> {"packets":{"0":{"tag":1,"version":3,"publicKeyId":{"bytes":"ošãï{m¹È"},"publicKeyAlgorithm":"rsa_encrypt_sign","sessionKey":null,"sessionKeyAlgorithm":"aes256","encrypted":[{"data":
>>>>>>
>>>>>> console.log( JSON.stringify(
>>>>>> pgpMessage['packets'][0]['publicKeyId']['bytes'] ) );
>>>>>> returns:
>>>>>>
>>>>>> "ošãï{m¹È"
>>>>>>
>>>>>> does this - "bytes" represent the publicKeyId and if so how do I
>>>>>> convert it into a format that I can compare with the actual publicKeyId
>>>>>> associated with the publicKey used for encryption?
>>>>>>
>>>>>> thanks.
>>>>>>
>>>>>> _______________________________________________
>>>>>>
>>>>>> http://openpgpjs.org
>>>>>> Subscribe/unsubscribe: http://list.openpgpjs.org
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>>
>>>>> http://openpgpjs.org
>>>>> Subscribe/unsubscribe: http://list.openpgpjs.org
>>>>>
>>>>
>>>> _______________________________________________
>>>>
>>>> http://openpgpjs.org
>>>> Subscribe/unsubscribe: http://list.openpgpjs.org
>>>
>>>
>> _______________________________________________
>>
>> http://openpgpjs.org
>> Subscribe/unsubscribe: http://list.openpgpjs.org
>>
>
>
_______________________________________________

http://openpgpjs.org
Subscribe/unsubscribe: http://list.openpgpjs.org

Reply via email to