Hi, dims:
I adopted the code in TestWSSecurityNew15.java that encrypts the soap body, but
I got the null pointer exception as the following:
Exception in thread "main" java.lang.NullPointerException
at
org.apache.ws.security.message.WSSecEncrypt.prepare(WSSecEncrypt.java:197)
at
com.nortel.cdma.axis.Client.NEServiceClient.main(NEServiceClient.java:240)
I looked at the line of code in WSSecEncrypt.java, it seems failed at
this.symmetricKey = keyGen.generateKey();
I suspect that keyGen is null. My code snips are as the following:
static final WSSecurityEngine secEngine = new WSSecurityEngine();
static final Crypto crypto =
CryptoFactory.getInstance("cryptoSKI.properties");
...
SOAPEnvelope env = new SOAPEnvelope(new ByteArrayInputStream(byteBuf));
WSSecEncrypt encrypt = new WSSecEncrypt();
encrypt.setUserInfo("wss4jcert", "security");
encrypt.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
encrypt.setSymmetricEncAlgorithm("WSConstants.TRIPLE_DES");
Document doc = env.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
encrypt.prepare(doc, crypto);
...
Do you have any idea whats wrong of my code?
Thanks,
Lule