1
10
11import java.io.FileInputStream;
12import java.io.ObjectInputStream;
13import java.io.FileOutputStream;
14import org.w3c.dom.Document;
15import javax.crypto.SecretKey;
16
17import com.verisign.xmlenc.Decryptor;
18import com.verisign.xpath.XPath;
19
20public class Decrypt {
21 public static void main(String[] args) throws Exception {
22 String encfile = "enc.xml";
24 String decfile = "dec.xml";
25 System.out.println("Decrypting file: " + encfile);
26
27 String keyfile = "3des.key";
29
30 FileInputStream fis = new FileInputStream(keyfile);
32 ObjectInputStream ois = new ObjectInputStream(fis);
33 SecretKey key = (SecretKey)ois.readObject();
34 System.out.println("Read key from file :" + keyfile);
35
36 Document doc = XmlUtility.readXML(encfile);
38
39 String[] ns = {"xenc", "http://www.w3.org/2001/04/xmlenc#"};
40 XPath encloc = new XPath("//xenc:EncryptedData", ns);
41
42 Decryptor decryptor = new Decryptor(doc, key, encloc);
43 Document decryptedDoc = decryptor.decrypt();
44
45 XmlUtility.writeXML(decryptedDoc, new FileOutputStream(decfile));
47
48 System.out.println();
49 System.out.println("Decryption SUCCESSFUL!!");
50 System.out.println("Decrypted document written to file: " + decfile);
51 }
52}