⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scar.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
// $Id: Scar.java,v 1.1.1.1 2002/08/27 12:32:15 grosbois Exp $//// $Log: Scar.java,v $// Revision 1.1.1.1  2002/08/27 12:32:15  grosbois// Add cryptix 3.2//// Revision 1.4  2000/08/17 11:41:04  edwin// java.* -> xjava.*//// Revision 1.3  1998/02/22 01:45:09  zox// Changed few privates to publics and cut down unnecesary output so it can be//   invoked from TestScar.//// Revision 1.2  1998/01/15 20:30:47  raif// *** empty log message ***//// Revision 1.1.1  1998/01/12  raif// + cosmetics.//// Revision 1.1  1997/12/30 11:05:36  raif// *** empty log message ***//// Revision 1.4.1  1997/12/29  raif// + modified to work with any security provider using the IJCE.// + added debugging and tracing.// + use SecureRandom to generate a random iv and use it as the first//   encryption block when creating the archive.  Recommended since we're//   using the cipher in CBC mode.  Doing so will generate a different//   output for the same input and key.// + renamed it 'scar' for Strong Cryptographic ARchiver!// + use OpenPGP-like simple/salted/iterated S2K algorithms. Used the//   draft-ietf-openpgp-formats.txt document dated November 97 for//   implementation details.// + embedded CryptorInputStream and CryptorOutputStream as inner classes//   and changed their names to ScarInputStream and ScarOutputStream//   respectively.// + added support for individual user-specific properties file.// + fixed some values that were platform specific.// + made it final.// + amended dox.//// Revision 1.4  1997/12/07 06:59:53  hopwood// + Committed changes below.//// Revision 1.3.1  1997/12/04  hopwood// + Changed variables to instance, not static.// + Fixed some typos.// + Added "to do" points in documentation (use random IV, iterate the//   hash function, use salt). Also added disclaimer, since it won't be//   cryptographically strong until these three points are fixed.// + Noted that the format may change incompatibly.// + Made this class non-public.//// Revision 1.3  1997/12/03 01:16:26  raif// *** empty log message ***//// Revision 1.2  1997/11/20 22:54:22  hopwood// + cryptix.util.* name changes.//// Revision 1.1  1997/11/07 14:32:46  raif// *** empty log message ***//// $Endlog$/* * Copyright (c) 1997, 1998 Systemics Ltd * on behalf of the Cryptix Development Team. All rights reserved. */package cryptix.tools;import cryptix.CryptixException;import cryptix.util.io.DosFilter;import cryptix.util.checksum.PRZ24;import cryptix.provider.key.RawKeyGenerator;import java.io.CharConversionException;import java.io.EOFException;import java.io.File;import java.io.FileInputStream;import java.io.FilenameFilter;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FilterInputStream;import java.io.FilterOutputStream;import java.io.InputStream;import java.io.IOException;import java.io.OutputStream;import java.io.PrintWriter;import java.io.PushbackInputStream;import xjava.security.Cipher;import xjava.security.CipherInputStream;import xjava.security.CipherOutputStream;import xjava.security.FeedbackCipher;import java.security.KeyException;import xjava.security.KeyGenerator;import java.security.InvalidKeyException;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import java.security.NoSuchProviderException;import java.security.SecureRandom;import xjava.security.SecretKey;import xjava.security.WeakKeyException;import java.util.MissingResourceException;import java.util.PropertyResourceBundle;import java.util.Vector;import java.util.zip.ZipEntry;import java.util.zip.ZipInputStream;import java.util.zip.ZipOutputStream;/** * A command line utility to (a) compress, encrypt and asciify files and/or * directories (with or without directory recursion), and (b) accomplish the * inverse with user-specified option for recreating a source tree directory.<p> * * Uses java.zip tools to deflate and inflate data, Cryptix IJCE for the cipher * and message digest (used to compute cipher keys from user plain ascii * passphrase) algorithms, and a PGP-style Base-64 armour with P. R. Zimmermann * 24-bit CRC method (PRZ24 class) for the [de-]asciification.<p> * * Hard-wired default values for cipher (Square) and Simple String To Key (S2K) * specifier with message digest (RIPEMD-160) algorithms are used. These and * other default values can be individually modified for each user by setting * the appropriate properties in a <i>scar.properties</i> file placed in the * user's home directory.<p> * * Current scar properties that the user can alter are: *      <dt>scar.header *      <dd>The text that will be enclosed between a pair of ----- to visually *          indicate the start of an asciified scar. Current default is "BEGIN *          SCAR ARCHIVE". * *      <dt>scar.comment *      <dd>A text that will follow the text "Comment: " in a line following *          scar version information in an asciified scar. Current default is *          "scar by Cryptix...". * *      <dt>scar.footer *      <dd>The text that will be enclosed between a pair of ----- to visually *          indicate the end of an asciified scar. Current default is "END SCAR *          ARCHIVE." * *      <dt>scar.cipher.algorithm *      <dd>The name of a symmetric cipher algorithm installed and accessible *          by the user Java VM. Current default is "Square".  Square is a *          symmetric block cipher algorithm developed by Joan Daemen *          <Daemen.J@banksys.com> and Vincent Rijmen *          <vincent.rijmen@esat.kuleuven.ac.be>. * *      <dt>scar.passphrase *      <dd>The text to use as the pass-phrase. This pass-phrase will be used *          as the basis for computing a session key. The algorithms used to *          generate a session key from the pass-phrase are an implementation *          of the proposed S2K Simple, Salted, Iterated and Salted-Iterated *          variations described in the OpenPGP IETF draft document dated *          November 1997.  The current default is "sub rosa." * *      <dt>scar.md.algorithm *      <dd>The Message Digest algorithm used in the S2K algorithms. "RIPEMD-160" *          Is the default. RIPEMD-160 is designed by Hans Dobbertin, Antoon *          Bosselaers and Bart Preneel. * *      <dt>scar.md.salt *      <dd>A salt value to use in S2K Salted and Iterated-Salted variants. *          Current value is "Cryptix Development Team". * *      <dt>scar.md.iterations *      <dd>A positive integer to use in S2K Iterated and Salted-Iterated *          variants. Current default value is 7. * * To do:<ul> *  <li>Add an option to allow use in distribution applications ('JAR' format *      with manifest file). *  <li> ... * </ul> * <strong>Note: <i>this is an alpha release of <i>scar</i>. The format of * encrypted archives may (and probably will) change incompatibly in future * releases.</i></strong>.<p> * * <b>Copyright</b> &copy; 1997, 1998 * <a href="http://www.systemics.com/">Systemics Ltd</a> on behalf of the * <a href="http://www.systemics.com/docs/cryptix/">Cryptix Development Team</a>. * <br>All rights reserved. * <p> * <b>$Revision: 1.1.1.1 $</b> * @author  Raif S. Naffah */public class Scarextends Thread{// Tracing and Debugging methods and fields//...........................................................................    public static boolean DEBUG = true;    static int debuglevel;    static final PrintWriter err = new PrintWriter(System.out, true);    static void debug (String s) { if (DEBUG) err.println(">>> scar: " + s); }    static final boolean TRACE = false;    static final boolean IN = true, OUT = false;    static void trace (boolean in, String s) {        if (TRACE) err.println((in ? "==> " : "<== ") + s); }    static void trace (String s) { if (TRACE) err.println("<=> " + s); }// main method//...........................................................................        public static void main (String[] args)    {        System.out.println(            "scar (Strong Cryptographic ARchiver)\n" +            VERSION + "\n" +            "Copyright (c) 1997, 1998 Systemics Ltd. on behalf of\n" +            "the Cryptix Development Team.  All rights reserved.\n\n");        Scar jc = new Scar();        jc.processOptions(args);        jc.run();    }// Constants and fields//...........................................................................    /** Current values of switches as set from the command line arguments. */    private boolean             // switch        asciify = false,        // -a  asciify        decrypting = false,     // -d  decrypt        encrypting = false,     // -e  encrypt        recursion = false,      // -r  recurse directories        useDirInfo = false,     // -u  use directory info        verbose = false,        // -v  verbose        wipeSource = false;     // -w  wipe source    /** Configured values of some main parameters set during this instance. */    private String        cipherAlgorithm = null, // -c  cipher; property key "scar.cipher.algorithm"        passPhrase = null,      // -p  passphrase; property key "scar.passphrase"        mdAlgorithm = null,     // -m  message digest; property key "scar.md.algorithm"        salt = null;            // -s  salt; property key "scar.md.salt"    private int iterations;     // -i  md iteration count; property key "scar.md.iterations"    private String        input = null,        output = null;    /** Some local vars for file/stream pipelining. */    private File        inFile =  null,        outFile = null,        temp =    null,        temp2 =   null;    /** Local buffer to speed compression, read, and write operations. */    private byte[] buffer = new byte[512];    /**     * A java.io.FilenameFilter to allow file name selection using DOS-style     * wildcards ('*' and '?').     */    private DosFilter filter = new DosFilter();    /** Number of files processed so far. */    private int count = 0;    /**     * Magic string that will be written to archive file at creation time     * and checked at decryption time to make sure the file was created     * by us. Saves time if the file is not ours or was peoduced with a     * different set of properties.     */    private static final String MAGIC_STRING = "Que du magnifique...";    private static final byte[] MAGIC = MAGIC_STRING.getBytes();    /**     * User ResourceBundle file for his/her scar.properties. Only     * user home directory is searched for this properties file.     */    PropertyResourceBundle properties;    //    // user specific properties and runtime jvm host-specific fields    //    /** User runtime jvm host file separator. */    static String fs;    /** Header info following ----- in an asciified scar file. */    String header; // property key "scar.header"    /** Footer info following ----- in an asciified scar file. */    String footer; // property key "scar.footer"    /** Comment data. */    String comment; // property key "scar.comment"    /** Source of randomness. */    static final SecureRandom random = new SecureRandom();    /** Default default values! */    static final String DEFAULT_HEADER =      "BEGIN SCAR ARCHIVE";    static final String DEFAULT_FOOTER =      "END SCAR ARCHIVE";    static final String DEFAULT_COMMENT =     "scar by Cryptix...";    static final String DEFAULT_CIPHER =      "Square";    static final String DEFAULT_PASS_PHRASE = "sub rosa";    static final String DEFAULT_MD =          "RIPEMD-160";    static final String DEFAULT_SALT =        "BEGIN SCAR ARCHIVE";    static final int DEFAULT_ITERATIONS =     7;    // Constructor//...........................................................................    public Scar ()    {        trace(IN, "Scar()");        //        // look for 'scar.properties' file in user.home        //        fs = System.getProperty("file.separator");        String home = System.getProperty("user.home");        try {                            // read user default scar properties            String resource = home + "scar.properties";            properties = new                PropertyResourceBundle(new FileInputStream(resource));        }        catch (FileNotFoundException ex1) {            debug("File \"scar.properties\" was not found in " + home +                ". Using default properties");            initDefaults();            trace(OUT, "Scar()");            return;        }        catch (IOException ex2) {            debug("I/O exception occured while loading \"scar.properties\"" +                " file. Using default properties");            initDefaults();            trace(OUT, "Scar()");            return;        }        //        // load properties setting hard-coded values if related        // property key was not found in the 'scar.properties' file        //        try { header = properties.getString("scar.header"); }        catch (MissingResourceException ex3) { header = DEFAULT_HEADER; }        try { footer = properties.getString("scar.footer"); }        catch (MissingResourceException ex4) { footer = DEFAULT_FOOTER; }        try { comment = properties.getString("scar.comment"); }        catch (MissingResourceException ex5) { comment = DEFAULT_COMMENT; }        try { cipherAlgorithm = properties.getString("scar.cipher.algorithm"); }        catch (MissingResourceException ex6) { cipherAlgorithm = DEFAULT_CIPHER; }        try { passPhrase = properties.getString("scar.passphrase"); }        catch (MissingResourceException ex7) { passPhrase = DEFAULT_PASS_PHRASE; }        try { mdAlgorithm = properties.getString("scar.md.algorithm"); }        catch (MissingResourceException ex8) { mdAlgorithm = DEFAULT_MD; }        try { salt = properties.getString("scar.md.salt"); }        catch (MissingResourceException ex9) { salt = DEFAULT_SALT; }        try { iterations = Integer.parseInt(properties.getString("scar.md.iterations")); }        catch (MissingResourceException ex10) { iterations = DEFAULT_ITERATIONS; }        debug("Default properties [...");        debug("      header line: \"-----" + header + "-----\"");        debug("     comment line: \"Comment: " + comment + "\"");        debug("      footer line: \"-----" + footer + "-----\"");        debug(" cipher algorithm: \"" + cipherAlgorithm + "\"");        debug("      pass-phrase: \"" + passPhrase + "\"");        debug("   message digest: \"" + mdAlgorithm + "\"");        debug("          md salt: \"" + salt + "\"");        debug("    md iterations: " + iterations);        debug("...]");        trace(OUT, "Scar()");    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -