KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > encrypt


1 /*
2  * encrypt.java
3  *
4  * Created on 12. Dezember 2005, 14:49
5  */

6 /*
7  * Copyright 2005 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 /**
28  * Encrypts the file provided as the first argument to its main method into an
29  * RAES file provided as the second argument.
30  * <p>
31  * Please note that you should not use this utility to encrypt a plain
32  * ZIP file to an RAES encrypted ZIP file (usually a files with a
33  * <code>".tzp"</code> or <code>".zip.rae"</code> suffix).
34  * This is because RAES encrypted ZIP files use the <code>UTF-8</code>
35  * as their character set encoding, whereas plain ZIP files use
36  * <code>IBM437</code>, a.k.a. <code>CP437</code>.
37  * To encrypt a plain ZIP file to an RAES encrypted ZIP file, use the
38  * <code>"cp"</code> command of the {@link nzip} class instead.
39  * This class knows about the correct character set encodings for the
40  * various flavours of ZIP compatible files.
41  *
42  * @author Christian Schlichtherle
43  */

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