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
Not sure if I'm doing something wrong, or if it's a bug.
I have an Ed25519 public key, that I have loaded from a byte array. Using the below encrypt(...) method to encrypt a byte array, but this exception gets thrown: Attempt to invoke virtual method 'org.bouncycastle.math.ec.ECCurve org.bouncycastle.asn1.x9.X9ECParameters.getCurve()' on a null object reference. Works fine using RSA keys.
Using 1.60.
final class PublicKey {
public PublicKey(PGPPublicKey publicKey) {
this.publicKey = publicKey;
}
PGPPublicKey publicKey;
static PublicKey fromBytes(byte[] input) throws PGPException, IOException {
InputStream inputStream = new ByteArrayInputStream(input);
JcaPGPPublicKeyRingCollection keyRings;
try {
keyRings = new JcaPGPPublicKeyRingCollection(inputStream);
}
finally {
inputStream.close();
}
Iterator<PGPPublicKeyRing> keyRingsIterator = keyRings.getKeyRings();
while (keyRingsIterator.hasNext())
{
PGPPublicKeyRing keyRing = keyRingsIterator.next();
Iterator<PGPPublicKey> publicKeysIterator = keyRing.getPublicKeys();
while (publicKeysIterator.hasNext())
{
PGPPublicKey publicKey = publicKeysIterator.next();
if (publicKey.isEncryptionKey())
return new PublicKey(publicKey);
}
}
throw new IllegalArgumentException();
}
public byte[] encrypt( final byte[] message)
throws IOException, PGPException
{
final ByteArrayInputStream in = new ByteArrayInputStream( message );
final ByteArrayOutputStream bOut = new ByteArrayOutputStream();
final PGPLiteralDataGenerator literal = new PGPLiteralDataGenerator();
final OutputStream pOut = literal.open(bOut, PGPLiteralData.BINARY, "filename", in.available(), new Date() );
Streams.pipeAll( in, pOut );
final byte[] bytes = bOut.toByteArray();
final PGPEncryptedDataGenerator generator = new PGPEncryptedDataGenerator(
new JcePGPDataEncryptorBuilder( SymmetricKeyAlgorithmTags.AES_256 ).setWithIntegrityPacket( true )
.setSecureRandom(
new SecureRandom() )
.setProvider(Utils.bouncyCastleProvider ) );
generator.addMethod( new JcePublicKeyKeyEncryptionMethodGenerator( this.publicKey ).setProvider( Utils.bouncyCastleProvider ) );
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStream cOut = generator.open( out, bytes.length );
cOut.write( bytes );
cOut.close();
out.close();
return out.toByteArray();
}
}
This was a bit complicated, GPG has started supporting Curve25519 but the private value is reversed (relative to the Java view of the world). I've adjusted the PGP API to take this into account so it should now be possible to process messages encrypted using Curve25519. It's in the current beta at https://www.bouncycastle.org/betas 161b25 or later.
Not sure if I'm doing something wrong, or if it's a bug.
I have an Ed25519 public key, that I have loaded from a byte array. Using the below encrypt(...) method to encrypt a byte array, but this exception gets thrown:
Attempt to invoke virtual method 'org.bouncycastle.math.ec.ECCurve org.bouncycastle.asn1.x9.X9ECParameters.getCurve()' on a null object reference
. Works fine using RSA keys.Using 1.60.
Stack trace:
org.bouncycastle.jcajce.provider.asymmetric.util.EC5Util.getCurve(Unknown Source:56), org.bouncycastle.jcajce.provider.asymmetric.ec.AlgorithmParametersSpi.engineInit(Unknown Source:12), org.bouncycastle.jcajce.provider.asymmetric.ec.AlgorithmParametersSpi.engineInit(Unknown Source:2), java.security.AlgorithmParameters.init(AlgorithmParameters.java:382), org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator.encryptSessionInfo(Unknown Source:48), org.bouncycastle.openpgp.operator.PublicKeyKeyEncryptionMethodGenerator.generate(Unknown Source:16), org.bouncycastle.openpgp.PGPEncryptedDataGenerator.open(Unknown Source:120), org.bouncycastle.openpgp.PGPEncryptedDataGenerator.open(Unknown Source:1)
Kind regards, Emil
The text was updated successfully, but these errors were encountered: