Skip to content

Commit d50e8bd

Browse files
author
gefeili
committed
Fix the exception message. Ensure array.copy in getPublicBCPGKey cannot cause out of bounds exception
1 parent a3df8e0 commit d50e8bd

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pg/src/main/java/org/bouncycastle/openpgp/operator/bc/BcPublicKeyDataDecryptorFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ else if (ecPubKey.getCurveOID().equals(EdECObjectIdentifiers.id_X448))
123123
{
124124
if (pEnc.length != 1 + X448PublicKeyParameters.KEY_SIZE || 0x40 != pEnc[0])
125125
{
126-
throw new IllegalArgumentException("Invalid Curve25519 public key");
126+
throw new IllegalArgumentException("Invalid Curve448 public key");
127127
}
128128
// skip the 0x40 header byte.
129129
secret = BcUtil.getSecret(new X448Agreement(), privKey, new X448PublicKeyParameters(pEnc, 1));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,10 +719,10 @@ private interface BCPGKeyOperation
719719

720720
private BCPGKey getPublicBCPGKey(PublicKey pubKey, int keySize, BCPGKeyOperation operation)
721721
{
722-
SubjectPublicKeyInfo pubInfo = SubjectPublicKeyInfo.getInstance(pubKey.getEncoded());
722+
byte[] pubInfo = SubjectPublicKeyInfo.getInstance(pubKey.getEncoded()).getPublicKeyData().getBytes();
723723
byte[] pointEnc = new byte[keySize];
724-
725-
System.arraycopy(pubInfo.getPublicKeyData().getBytes(), 0, pointEnc, 0, pointEnc.length);
724+
// refer to getPointEncUncompressed
725+
System.arraycopy(pubInfo, 0, pointEnc, pointEnc.length - pubInfo.length , pubInfo.length);
726726
return operation.getBCPGKey(pointEnc);
727727
}
728728

0 commit comments

Comments
 (0)