[prev in list] [next in list] [prev in thread] [next in thread]
List: bouncycastle-crypto-dev
Subject: [dev-crypto] Problem with Key ID to retrieve Public Key?
From: Munna2002 <ganesh.kumar () lehman ! com>
Date: 2008-02-29 20:24:31
Message-ID: 15765118.post () talk ! nabble ! com
[Download RAW message or body]
Hello,
I'm unable to extract the keys from a keyring given keyIDs generated from
PGP Desktop. I've an existing pubring.pkr and secring.skr that contains
public keys and secret keys respectively that were created by PGP Desktop.
Using PGP Desktop on the command line with [pgp -kvv ""
"C:\PGP\pubring.pkr"], I get the following truncated output:
=========================
C:\PGP>pgp -kvv "" "C:\PGP\pubring.pkr"
Pretty Good Privacy(tm) Version 6.5.2
Key ring: 'c:\pgp\pubring.pkr'
Type bits keyID Date User ID
DSS 1024 0xF162B13F 2000/01/11
DH 2048 0xF162B13F 2000/01/11 Accounting
sig 0xF162B13F Accounting
sig 0xF04F424F blah@blah.com
RSA 1024 0xBB6615F3 2007/07/05 advent
sig 0xBB6615F3 advent
DSS 1024 0xD4AF3311 2006/04/25
DH 2048 0xD4AF3311 2006/04/25 Company
sig 0xD4AF3311 Company
sig 0xF04F424F blah@blah.com
=========================
However when I try the same keyIDs like "0xF162B13F" with tihs command
"key.getKeyID()", I am not able to get a key and I get null instead. When I
print out the keys for all of the keyIDs, they do not match the long value
or hex value of the PGP Desktop output from above. How do I convert or
extract the appropriate key using the "getKeyID()" command that correspond
to PGP Desktop's output? My code and output are posted below. Any help is
appreciated. Thanks in advance.
==========================
Code:
public static void readPublicKeyKeyIDTest(InputStream in) throws Exception
{
PGPPublicKeyRingCollection pkCol = new PGPPublicKeyRingCollection(in);
// ATTEMPTING TO RETRIEVE ACCOUNTING KEY WITH KEY 0xF162B13F
PGPPublicKey retrievedKey = null;
System.out.println("Retrieving KeyID 0xF162B13F =
"+Long.parseLong("F162B13F",16));
retrievedKey = pkCol.getPublicKey(Long.parseLong("F162B13F", 16));
System.out.println("Retrieved Key = "+retrievedKey); // THIS SHOULD NOT BE
NULL BUT IT IS
// ATTEMPTING TO RETRIEVE ACCOUNTING KEY WITH KEY 0xF162B13F
Long testLong = new Long(0xF162B13F);
System.out.println("Retrieving KeyID 0xF162B13F = "+ testLong);
retrievedKey = pkCol.getPublicKey(testLong);
System.out.println("Retrieved Key = "+retrievedKey); // THIS SHOULD NOT BE
NULL BUT IT IS
System.out.println("=========================");
System.out.println("key ring size=" + pkCol.size());
Iterator it = pkCol.getKeyRings();
PGPPublicKeyRing pkRing = null;
PGPPublicKey matchedKey = null;
int keyRingCounter = 0;
while (it.hasNext())
{
pkRing = (PGPPublicKeyRing) it.next();
Iterator pkIt = pkRing.getPublicKeys();
System.out.println("KeyRing Counter: "+(++keyRingCounter));
System.out.println("KeyRing toString:"+pkRing.toString());
System.out.println("KeyRing Key ID:"+pkRing.getPublicKey().getKeyID());
int keyCounter = 0;
while (pkIt.hasNext())
{
PGPPublicKey key = (PGPPublicKey) pkIt.next();
System.out.println("\tSubKeyRing "+(++keyCounter)+":\tEncryption key = "
+ key.isEncryptionKey() + ", Master key = " + key.isMasterKey());
System.out.println("\t\t"+"Algorithm:"+key.getAlgorithm());
System.out.println("\t\t"+"Bit Strength:"+key.getBitStrength());
System.out.println("\t\t"+"Key ID:"+key.getKeyID()+" = Hex
"+Long.toHexString(key.getKeyID())); // THESE SHOULD MATCH WITH PGP DESKTOP
KEY IDS BUT THEY DO NOT
Iterator userIDIt = key.getUserIDs();
int UIcounter = 0;
while(userIDIt.hasNext())
{
System.out.println("\tUser ID "+(++UIcounter)+": "+userIDIt.next());
}
if (key.isEncryptionKey())
matchedKey = key;
testLong = key.getKeyID();
}
}
}
==========================
Output of Code:
true
true
pubring.pkr
secring.skr
Retrieving KeyID 0xF162B13F = 4049776959
Retrieved Key = null
Retrieving KeyID 0xF162B13F = -245190337
Retrieved Key = null
------ KEY RING OUTPUT ---------
KeyRing Counter: 1
KeyRing toString:org.bouncycastle.openpgp.PGPPublicKeyRing@16930e2
KeyRing Key ID:3665695483845849407
SubKeyRing 1: Encryption key = false, Master key = true
Algorithm:17
Bit Strength:1024
Key ID:3665695483845849407 = Hex 32df2a9ef162b13f
User ID 1: Accounting
SubKeyRing 2: Encryption key = true, Master key = false
Algorithm:16
Bit Strength:2048
Key ID:4749113433791723950 = Hex 41e83d819330f9ae
KeyRing Counter: 2
KeyRing toString:org.bouncycastle.openpgp.PGPPublicKeyRing@131f71a
KeyRing Key ID:-7348895606764071437
SubKeyRing 1: Encryption key = true, Master key = true
Algorithm:1
Bit Strength:1024
Key ID:-7348895606764071437 = Hex 9a037a61bb6615f3
User ID 1: advent
KeyRing Counter: 3
KeyRing toString:org.bouncycastle.openpgp.PGPPublicKeyRing@a39137
KeyRing Key ID:2568624006897808145
SubKeyRing 1: Encryption key = false, Master key = true
Algorithm:17
Bit Strength:1024
Key ID:2568624006897808145 = Hex 23a595ecd4af3311
User ID 1: Company
SubKeyRing 2: Encryption key = true, Master key = false
Algorithm:16
Bit Strength:2048
Key ID:-4595178098156688249 = Hex c03aa5ddb3b72c87
--
View this message in context: \
http://www.nabble.com/Problem-with-Key-ID-to-retrieve-Public-Key--tp15765118p15765118.html
Sent from the Bouncy Castle - Dev mailing list archive at Nabble.com.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic