Skip to content

Commit 7f286f8

Browse files
committed
Prevent conversion issue for EdDSA keys with leading 0
1 parent ccfb9ef commit 7f286f8

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

pg/src/main/java/org/bouncycastle/openpgp/operator/jcajce/JcaPGPKeyConverter.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,22 +367,13 @@ else if (ecdhK.getCurveOID().equals(EdECObjectIdentifiers.id_X448))
367367
// Modern Ed25519 (1.3.6.1.4.1.11591.15.1 & 1.3.101.112)
368368
case PublicKeyAlgorithmTags.Ed25519:
369369
{
370-
BCPGKey key = publicPk.getKey();
371-
if (key instanceof Ed25519PublicBCPGKey)
372-
{
373-
return implGetPublicKeyX509(BigIntegers.asUnsignedByteArray(new BigInteger(1, publicPk.getKey().getEncoded())),
374-
0, EdECObjectIdentifiers.id_Ed25519, "EdDSA");
375-
}
376-
else
377-
{
378-
return implGetPublicKeyX509(BigIntegers.asUnsignedByteArray(((EdDSAPublicBCPGKey)publicPk.getKey()).getEncodedPoint()),
370+
return implGetPublicKeyX509(publicPk.getKey().getEncoded(),
379371
0, EdECObjectIdentifiers.id_Ed25519, "EdDSA");
380-
}
381372
}
382373
// Modern Ed448 (1.3.101.113)
383374
case PublicKeyAlgorithmTags.Ed448:
384375
{
385-
return implGetPublicKeyX509(BigIntegers.asUnsignedByteArray(new BigInteger(1, publicPk.getKey().getEncoded())),
376+
return implGetPublicKeyX509(publicPk.getKey().getEncoded(),
386377
0, EdECObjectIdentifiers.id_Ed448, "EdDSA");
387378
}
388379
case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT:

0 commit comments

Comments
 (0)