4

In algorythmic level it is possible to restore public key from private. But is there a way to do it in bouncycastle library with PGP keys?

Thanks!

Mitya XMitya
  • 1,129
  • 9
  • 17
  • What input do you have? PGP secret key files typically contain the public key, so no recovery would be necessary in that case. Knowing what your input is would help with providing an accurate answer. – Duncan Jones Oct 27 '12 at 17:01
  • I have two separate files: PGPPublicKey and PGPPrivateKey. I dont't save PGPSecretKey. Maybe it would be better to use secret key instead of private? But I always kept in mind that it should be a way to restore public key from private. – Mitya XMitya Oct 27 '12 at 17:27

1 Answers1

1

in PGPPrivateKey there is the method getPublicKeyPacket, which in turn has the method getKey.

Isn't it what you're looking for?

jdevelop
  • 12,176
  • 10
  • 56
  • 112
  • It seems yes. I use 1.40 version of bouncycastle and it doesn't have such method, but it's available in latest version. Thank you! – Mitya XMitya Oct 27 '12 at 19:13
  • For me `getPublicKeyPacket().getKey()` returns `BCPGKey` not `PGPPublicKey` – Eun Feb 20 '15 at 08:38
  • I used `new PGPPublicKey(privateKey.getPublicKeyPacket(), new JcaKeyFingerprintCalculator());` to get the `PGPPublicKey` – Eun Feb 20 '15 at 08:45