EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Issues With Using FindPublicKeyByID

Posted: 05/09/2012 14:27:42
by Christopher Kowitz (Standard support level)
Joined: 05/08/2012
Posts: 5

I read this posting "How Do You Use FindPublicKeyByID ??" and the documentation for FindPublicKeyByID. As I understand it I convert the 16 character KeyID to an 8 byte array. I seem to have this working. But it says that there may be duplicates, which I don't understand. But the documentation says that you have to loop through the results from FindPublicKeyByID until you find the key that you want by changing the StartIndex. So I started at 0 and it return an Index of 1, when isn't the key that I wanted. So I call the function again passing in a start index of 1 and it returned 1 again. Then I changed the start index to 2 and it returned 1 again. What am I missing here and what is the best way of retrieving the key that I need to encrypt or sign? The other thing that's confusing is that our old software we could do a lookup with 'Ox7721BADB' and get the correct key, now I'm passing 16 characters and I get multiple matches.

Posted: 05/09/2012 16:28:49
by Ken Ivanov (Team)

Thank you for contacting us.

In fact, the method works in slightly different way. FindPublicKeyByID() returns the total number of keys matching the provided ID. The StartIndex'th key is returned via the Res parameter.

This way, the results you are getting are consistent. FindPublicKeyByID() always returns 1 as there is only one key in the keyring that corresponds to the supplied Key ID. The Res parameters is assigned with that key object if StartIndex is 0, and is set to null if StartIndex is 1, 2 and greater.
Posted: 05/10/2012 06:49:28
by Christopher Kowitz (Standard support level)
Joined: 05/08/2012
Posts: 5

Thanks. That clears a few things up. One more question since the function is returning a CustomPublicKey can I just add it into my PublicKeyRing for encryption? or Do I need to cast or convert it somehow into a PublicKey?

Thanks again.
Posted: 05/10/2012 06:58:03
by Vsevolod Ievgiienko (Team)


You can typecast TElPGPCustomPublicKey to TElPGPPublicKey and then add to another TElPGPKeyring.
Posted: 05/10/2012 07:25:20
by Ken Ivanov (Team)

You should be prepared to get either TElPGPPublicKey or TElPGPPublicSubkey object from this method (as keys and subkeys have different and independent IDs). If the returned object is of TElPGPPublicSubkey type, you can get the main key via its SupKey property.
Posted: 05/10/2012 08:52:58
by Christopher Kowitz (Standard support level)
Joined: 05/08/2012
Posts: 5

Excellent, thanks for all of your help.



Topic viewed 700 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!