I am currently developing an integration code where in before sending the request XML I need to digitally sign it. I have researched a lot over it.
Initial xml:
<?xml version ="1.0" encoding="utf-8">
<command>
some xml
</command>
Resultant xml must be:
<?xml version="1.0" encoding ="utf-8">
<command>
some xml...
<signature>
some signature value...
</signature>
</command>
The code I am using is:
`SecureRandom secureRandom = new SecureRandom();
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
KeyPair keyPair = keyPairGenerator.generateKeyPair();
Signature signature = Signature.getInstance("SHA1WithRSA");
signature.initSign(keyPair.getPrivate(), secureRandom);
byte[] data = myxmlstring.getBytes("UTF-8");
signature.update(data);
byte[] digitalSignature = signature.sign();
- All the help is showing me above kind of code.
- I am completely new to Java cryptography.
- I have to sign the xml using private key and share the public key to the middleware for verification.
- I need to understand how to generate key store, key pair and certificates, use the keys and how to share the public key with the middleware.