13
13
import javax .xml .parsers .DocumentBuilderFactory ;
14
14
15
15
import java .util .List ;
16
+ import java .util .Properties ;
16
17
import java .io .ByteArrayInputStream ;
17
18
import java .io .InputStream ;
18
19
import java .io .IOException ;
@@ -27,14 +28,16 @@ public static void main(String[] args)
27
28
{
28
29
try
29
30
{
31
+ System .setProperty ("logfilename" , args [2 ]);
32
+
30
33
List <String > lines = Files .readAllLines (Paths .get (args [0 ]), Charset .defaultCharset ());
31
34
String encrypted_xml = "" ;
32
35
for (String line : lines )
33
36
{
34
37
encrypted_xml += line ;
35
38
}
36
39
37
- String document = decrypt (encrypted_xml );
40
+ String document = decrypt (encrypted_xml , args [ 1 ] );
38
41
System .out .println (document );
39
42
}
40
43
catch (Exception e )
@@ -53,12 +56,35 @@ public static Document getSOAPDoc(String document) throws Exception
53
56
return doc ;
54
57
}
55
58
56
- public static String decrypt (String encryptedXml ) throws Exception {
57
- Crypto crypto = CryptoFactory .getInstance ();
59
+ public static Crypto getSigningCrypto (String keyfile ) throws Exception {
60
+ Properties properties = new Properties ();
61
+ properties .setProperty ("org.apache.ws.security.crypto.provider" , "org.apache.ws.security.components.crypto.Merlin" );
62
+ properties .setProperty ("org.apache.ws.security.crypto.merlin.keystore.file" , keyfile );
63
+ properties .setProperty ("org.apache.ws.security.crypto.merlin.keystore.password" , "importkey" );
64
+ properties .setProperty ("org.apache.ws.security.crypto.merlin.keystore.private.password" , "importkey" );
65
+ properties .setProperty ("org.apache.ws.security.crypto.merlin.keystore.alias" , "vbms_server_key" );
66
+
67
+ return CryptoFactory .getInstance (properties );
68
+ }
69
+
70
+ public static Crypto getDecryptionCrypto (String keyfile ) throws Exception {
71
+ Properties properties = new Properties ();
72
+ properties .setProperty ("org.apache.ws.security.crypto.provider" , "org.apache.ws.security.components.crypto.Merlin" );
73
+ properties .setProperty ("org.apache.ws.security.crypto.merlin.keystore.file" , keyfile );
74
+ properties .setProperty ("org.apache.ws.security.crypto.merlin.keystore.password" , "importkey" );
75
+ properties .setProperty ("org.apache.ws.security.crypto.merlin.keystore.private.password" , "importkey" );
76
+
77
+ return CryptoFactory .getInstance (properties );
78
+ }
79
+
80
+ public static String decrypt (String encryptedXml , String keyfile ) throws Exception {
81
+ Crypto signCrypto = getSigningCrypto (keyfile );
82
+ Crypto deCrypto = getDecryptionCrypto (keyfile );
58
83
CallbackHandler handler = new WSSCallbackHandler ();
59
84
WSSecurityEngine secEngine = new WSSecurityEngine ();
85
+
60
86
Document doc = getSOAPDoc (encryptedXml );
61
- java .util .List <WSSecurityEngineResult > results = secEngine .processSecurityHeader (doc , null , handler , crypto , crypto );
87
+ java .util .List <WSSecurityEngineResult > results = secEngine .processSecurityHeader (doc , null , handler , signCrypto , deCrypto );
62
88
return XMLUtils .PrettyDocumentToString (doc );
63
89
}
64
90
0 commit comments