Search code examples
encryptionmulebouncycastlepgp

Mule: PGP decryption giving error message Invalid PGP message


Implementing mule pgp encryption decryption for an xml file. While decryption its raises an error

ERROR 2015-06-05 12:06:34,192 [Thread-8] org.mule.module.pgp.AbstractTransformPolicy: Invalid PGP message

java.lang.IllegalArgumentException: Invalid PGP message
    at org.mule.module.pgp.DecryptStreamTransformer.initialize(DecryptStreamTransformer.java:79)
    at org.mule.module.pgp.TransformContinuouslyPolicy$ContinuousWork.execute(TransformContinuouslyPolicy.java:60)
    at org.mule.module.pgp.AbstractTransformPolicy$TransformerWork.run(AbstractTransformPolicy.java:109)

I debugged mule pgp package and in DecryptStreamTransformer

public void initialize(OutputStream out) throws Exception
    {
        InputStream decodedInputStream = PGPUtil.getDecoderStream(this.toBeDecrypted);
        PGPObjectFactory pgpF = new PGPObjectFactory(decodedInputStream);
        Object o = pgpF.nextObject();

        if (o == null)
        {
            throw new IllegalArgumentException("Invalid PGP message");
        }

What might be the reasons of PGPObjectFactory returning nextObject as null. Also logging message payload after flow element

 <decrypt-transformer name="decryptTransformer" strategy-ref="pgpEncryptionStrategy"/>
<logger level="INFO" doc:name=" Message Logger" message="#[payload]"/>
<mulexml:jaxb-xml-to-object-transformer
            jaxbContext-ref="jaxb" doc:name="JAXB-Unmarshaller"
            returnClass="com.generated.Communication" />

Payload is displayed as org.mule.module.pgp.LazyTransformedInputStream@17d80e9.

How can i modify this instance to xml so that mulexml jaxb element can marshall this to required object.


Solution

  • As seen in its source code:

    registerSourceType(DataTypeFactory.INPUT_STREAM);
    

    the jaxb-xml-to-object-transformer accepts any input stream as a valid source, so the issue is not there.