为SOAP标头生成证书

时间:2013-08-09 11:30:38

标签: java soap-client

当我尝试使用以下代码生成代码时:

Certificate cert;

                InputStream path = new FileInputStream(TRUSTSTORE_LOCATION);
                KeyStore ks = KeyStore.getInstance("JKS");
                ks.load(path, TRUSTSTORE_PASS.toCharArray());

                // jak argument podaje sie certyfikat ktory jest zawarty w pliku trustory.jks
                cert = ks.getCertificate("xxxx");
                binarySecurityTokenElement.addTextNode(new BASE64Encoder().encode(cert.getEncoded()));
                //kpg = KeyPairGenerator.getInstance("DSA");
                kpg = KeyPairGenerator.getInstance("RSA");

输出结果为:

<wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" 
                          Id="X509-7E20D88DE75F0EAADA137595678499810" 
                          ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">
                                MIIDXDCCAkSgAwIBAgIEUFbpiDANBgkqhkiG9w0BAQUFADBwMQswCQYDVQQGEwJQTDEQMA4GA1UE&#13;
                                CBMHVW5rbm93bjENMAsGA1UEBxMETG9kejEVMBMGA1UEChMMQU1HLm5ldCBTLkEuMRUwEwYDVQQL&#13;
                        [...]

在行尾是这个“&#13;”,如何删除?

1 个答案:

答案 0 :(得分:1)

Base64Converter base = new Base64Converter();
String encodeCertyficate = base.encode(cert.getEncoded());
encodeCertyficate = encodeCertyficate.replace("\r", "").replace("\n", "");
binarySecurityTokenElement.addTextNode(encodeCertyficate);