KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > decrypt


1 /*
2  * decrypt.java
3  *
4  * Created on 12. Dezember 2005, 16:39
5  */

6 /*
7  * Copyright 2005-2006 Schlichtherle IT Services
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 import de.schlichtherle.io.*;
23 import de.schlichtherle.io.File;
24
25 import java.io.*;
26
27 import javax.swing.*;
28
29 /**
30  * Decrypts the RAES file provided as the first argument to the main
31  * method back into its content file provided as the second argument.
32  * <p>
33  * Please note that you should not use this utility to decrypt an RAES
34  * encrypted ZIP file (usually a file with a <code>".tzp"</code> or
35  * <code>".zip.rae"</code> suffix) back to a plain ZIP file.
36  * This is because RAES encrypted ZIP files use the <code>UTF-8</code>
37  * as their character set encoding, whereas plain ZIP files use
38  * <code>IBM437</code>, a.k.a. <code>CP437</code>.
39  * To decrypt an RAES encrypted ZIP file to a plain ZIP file, use the
40  * <code>"cp"</code> command of the {@link nzip} class instead.
41  * This class knows about the correct character set encodings for the
42  * various flavours of ZIP compatible files.
43  *
44  * @author Christian Schlichtherle
45  */

46 public class decrypt {
47     private static final nzip.ProgressMonitor progressMonitor
48             = new nzip.ProgressMonitor();
49     
50     public static void main(final String JavaDoc[] args) throws IOException {
51         if (args.length != 2)
52             usage();
53
54         nzip.configKeyManager();
55
56         if (new File(args[1]).isEntry())
57             progressMonitor.start();
58
59         try {
60             RaesFileUtils.decrypt(args[0], args[1], true);
61         } finally {
62             // Just in case our output file is located in a ZIP compatible file.
63
try {
64                 File.umount();
65             } finally {
66                 progressMonitor.interrupt();
67             }
68         }
69     }
70     
71     private static void usage() {
72         System.err.println(
73                 "decrypt (@version@)\n" +
74                 "Copyright 2005-2006 Schlichtherle IT Services\n\n" +
75                 "Unwraps the content from an RAES encrypted file.\n\n" +
76                 "Usage: decrypt SRC DST\n\n" +
77                 "where SRC is the encrypted file to unwrap and DST is the resulting content file.\n" +
78                 "Please note that both files may actually be located in a ZIP file (.zip suffix)\n" +
79                 "or an RAES encrypted ZIP file (.tzp suffix).");
80         System.exit(1);
81     }
82 }
83
Popular Tags