I receive a request from a client and after some masking the data I forward the request to web services. In order for the web service to allow me, I have to send to the <wsse: BinarySecurityToken> element. I have a .pfx certificate file, and from this certificate I need to create a security token. The rest of the request is created through SAAJ
<wsse:BinarySecurityToken>my security token</wsse:BinarySecurityToken>
How to generate a "security token" from a .pfx file?
Demo code:
InputStream inStream = new FileInputStream("C:\\development\\certs\\cert.pfx");
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(inStream, "PASSWORD".toCharArray());
Enumeration<String> aliases = ks.aliases();
String aliaz = "";
while(aliases.hasMoreElements()){
aliaz = aliases.nextElement();
if(ks.isKeyEntry(aliaz)){
break;
}
}
X509Certificate certificate = (X509Certificate) ks.getCertificate(aliaz);
Base64 base64 = new Base64();
String token = base64.encodeToString(certificate.getSignature())
The token parameter does not seem to match the token created from SOAPUI. Any help is greatly appreciated. Thank!
Roopa source
share