You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JcaPGPKeyConverter incompatible with Thales JCA LunaProvider and RSA key pair generation #2195
com.safenetinc.luna.exception.LunaException: Cannot access sensitive attributes...
at com.safenetinc.luna.provider.key.LunaPrivateKeyRsa.getPrivateExponent(LunaPrivateKeyRsa.java:37)
at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter.getPrivateBCPGKey(Unknown Source)
at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter.getPGPPrivateKey(Unknown Source)
at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair.getPrivateKey(Unknown Source)
at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair.<init>(Unknown Source)
at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPairGeneratorProvider$JcaPGPKeyPairGenerator.generateRsaKeyPair(Unknown Source)
at org.bouncycastle.openpgp.operator.PGPKeyPairGenerator.generateRsaKeyPair(Unknown Source)
at <lambda>
...
This is because LunaPrivateKeyRsa throws a new LunaException("Cannot access sensitive attributes...") in all methods exposing sensitive parts of the key:
changed the title [-]`JcaPGPKeyConverter` incompatible with Thales JCA `LunaProvider`[/-][+]`JcaPGPKeyConverter` incompatible with Thales JCA `LunaProvider` and RSA key pair generation[/+]on Nov 10, 2025
It's a HSM key, it's not going to provide the information required to produce a PGP encoding. Try using JcaPGPPrivateKey directly, you'll need to calculate the keyID for the public key as but you should be able to do that using the converter.
With this protocol extension it would be possible to create secret key packets which do not contain actual secret key material.
Instead, the secret key packet would hint that the private key is stored on some hardware device.
There is a chance that the OpenPGP WG might adopt the draft for an official RFC.
GnuPG already has a similar mechanism (GNU_DUMMY_S2K) that is already present in BC, although not yet utilized.
Adding hardware key support to BC requires some smaller changes, which I'm currently exploring.
Hi all, can I help somehow to move this topic forward?
We're considering overriding parts of BouncyCastle to make this work at a lower level, but I'd be much happier if we could just wire the vendor JCA without any customizations on top of BC.
Do you mean generating the RSA key without BC involvement? No, I didn't understand that last time from your message, but I'll try and let you know. Thanks!
Activity
[-]`JcaPGPKeyConverter` incompatible with Thales JCA `LunaProvider`[/-][+]`JcaPGPKeyConverter` incompatible with Thales JCA `LunaProvider` and RSA key pair generation[/+]dghgit commentedon Nov 12, 2025
It's a HSM key, it's not going to provide the information required to produce a PGP encoding. Try using JcaPGPPrivateKey directly, you'll need to calculate the keyID for the public key as but you should be able to do that using the converter.
vanitasvitae commentedon Nov 28, 2025
That's not totally correct.
Regarding HSM/TPM keys, I'm considering adding support for https://www.ietf.org/archive/id/draft-dkg-openpgp-hardware-secrets-02.html
With this protocol extension it would be possible to create secret key packets which do not contain actual secret key material.
Instead, the secret key packet would hint that the private key is stored on some hardware device.
There is a chance that the OpenPGP WG might adopt the draft for an official RFC.
GnuPG already has a similar mechanism (GNU_DUMMY_S2K) that is already present in BC, although not yet utilized.
Adding hardware key support to BC requires some smaller changes, which I'm currently exploring.
scordio commentedon Oct 22, 2026
Hi all, can I help somehow to move this topic forward?
We're considering overriding parts of BouncyCastle to make this work at a lower level, but I'd be much happier if we could just wire the vendor JCA without any customizations on top of BC.
dghgit commentedon Oct 22, 2026
Did you try using JcaPGPPrivateKey directly after generating the key pair with the HSM provider?
scordio commentedon Oct 22, 2026
Do you mean generating the RSA key without BC involvement? No, I didn't understand that last time from your message, but I'll try and let you know. Thanks!