/* * CryptoFileExternal.java * * * ==================================================== Professional Data Security (PDS) http://crypto.brettlee.com ==================================================== Copyright (c) 2009-2011, Brett Lee All rights reserved. Portions Copyright (C) 1995-2008, Sun Microsystems, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the ORGANIZATION nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ============================================================================= */ package com.brettlee.crypto; import javax.swing.JFrame; public class CryptoFileExternal extends CryptoFile { String encFilePath; String decFileName; String decFilePath; int compressionLevel; // 0 - 9 // ************************************************************** // Below is a scheme that is a serious candidate for refactoring. // Need a much more expressive approach. // ************************************************************** // 0 = File = kDEVICE_FILE; 1 = Raw Device = kDEVICE_RAW int deviceType; public static final int kDEVICE_FILE = 0; public static final int kDEVICE_RAW = 1; // 0 = Base64 = kBASE64; 1 = Binary = kBINARY; 2 = Zip = kZIP int encryptedOutputFormat; public static final int kBASE64 = 0; public static final int kBINARY = 1; public static final int kZIP = 2; // 0 = Decrypt and Extract = kDECRYPT_EXTRACT; 1 = Decrypt to Zip File = kDECRYPT_TOZIP int decryptedOutputFormat; public static final int kDECRYPT_EXTRACT = 0; public static final int kDECRYPT_TOZIP = 1; // 0 = kREQUESTED_FILE; 1 = kREQUESTED_DIRECTORY int decryptionTypeRequested; public static final int kREQUESTED_FILE = 0; public static final int kREQUESTED_DIR = 1; // Constructor public CryptoFileExternal() { cryptoFileId = StateObject.random.nextInt(); } // Setters && Getters // void setEncFilePath(String s) { encFilePath = s; } String getEncFilePath() { return encFilePath; } void setDecFilePath(String s) { decFilePath = s; } String getDecFilePath() { return decFilePath; } void setEncryptedOutputFormat(int n) { encryptedOutputFormat = n; } int getEncryptedOutputFormat() { return encryptedOutputFormat; } void setDecryptedOutputFormat(int n) { decryptedOutputFormat = n; } int getDecryptedOutputFormat() { return decryptedOutputFormat; } void setCompressionLevel(int n) { compressionLevel = n; } int getCompressionLevel() { return compressionLevel; } void setDecryptionTypeRequested (int n) { decryptionTypeRequested = n; } int getDecryptionTypeRequested () { return decryptionTypeRequested; } void setDeviceType(int n) { deviceType = n; } int getDeviceType() { return deviceType; } /** * Encrypt an external file * */ boolean encryptFile( CryptoFileExternal cryptoFile ) { // Status check - debugging // // System.out.println("In CryptoFileExternal().encryptFile()..."); // System.out.println("File to encrypt: " + cryptoFile.getFullyPathedFileName() ); // System.out.println(); // System.out.println("CryptoFile File : " + cryptoFile.getFullyPathedFileName() ); // System.out.println("CryptoFile KeyStore Name : " + cryptoFile.getKsName() ); // System.out.print("KeyStore Passphrase: "); // if ( cryptoFile.getKsPass() != null ) { // for ( int i=0; i < cryptoFile.getKsPass().length; i++ ) { // System.out.print( cryptoFile.getKsPass()[i] ); // } // } // System.out.println(); // Define as an Encrypt Action // cryptoFile.setAction( 0 ); // System.out.println("Defining the Action to perform (0=encrypt, 1=decrypt) : " + cryptoFile.getAction() ); // Run in a new thread - error reporting in the new Thread // Runnable encryptJob = new CryptoEngine( (CryptoFile) cryptoFile ); Thread t = new Thread( encryptJob ); t.start(); return true; } /** * Decrypt an external file * */ boolean decryptFile( CryptoFileExternal cryptoFile ) { // Status check - debugging // // System.out.println("In CryptoFileNative().decryptFile()..."); // System.out.println("File to decrypt: " + cryptoFile.getFullyPathedFileName() ); // Collect credentials // JFrame frame = new JFrame(); new AuthDialog(frame, true, 6, cryptoFile); // Was the Auth Dialog action canceled if ( StateObject.getFileChooserCancel() ) { return false; } // More checking - debugging // // System.out.println("After AuthDialog"); // System.out.println("CryptoFile File : " + cryptoFile.getFullyPathedFileName() ); // System.out.println("CryptoFile KeyStore Name : " + cryptoFile.getKsName() ); // System.out.print("KeyStore Passphrase: "); // if ( cryptoFile.getKsPass() != null ) { // for ( int i=0; i < cryptoFile.getKsPass().length; i++ ) { // System.out.print( cryptoFile.getKsPass()[i] ); // } // } // System.out.println(); // Define as a Decrypt Action // cryptoFile.setAction( 1 ); // System.out.println("Defining the Action to perform (0=encrypt, 1=decrypt) : " + cryptoFile.getAction() ); // Run in a new thread - error reporting in the new Thread // Runnable decryptJob = new CryptoEngine( (CryptoFile) cryptoFile ); Thread t = new Thread( decryptJob ); t.start(); return true; } }