public class TomsCrypter extends Object
// Encrypt String encryptedFilename = instance.encrypt(instance.getloadFilePath()); if (encryptedFilename!=null && !encryptedFilename.equals("")) { // Send File to GDrive instance.setloadFilePath(encryptedFilename); File uploadedFile = instance.uploadFile(false); }
Modifier and Type | Field and Description |
---|---|
private static String |
APPLICATION_NAME |
private static Cipher |
cipher |
private static String |
CLASSNAME
A holder This classes name (used when logging).
|
static String |
CLASSPATH
The VM classpath (used in some methods)..
|
private File |
dataStoreDir_
Directory to store user credentials.
|
private static String |
DEFAULT_DATASTORE_DIR |
private static String |
DEFAULT_DOWNLOAD_DIR |
private static String |
DEFAULT_LOAD_FILENAME |
private String |
dirForDownload_ |
private static String |
ECRYPT_FILEMARKER_DEFAULT
The Extension to use on the filename to markk it as AESEncrypted.
|
private String |
eCryptPass
Password for the AES Encryption
|
private String |
encryptFilemarker_
Filename suffix for the encrypted file.
|
(package private) String |
jceKey1 |
(package private) String |
jceKey2 |
private File |
loadFile_ |
private String |
loadFilePath_ |
static String |
SYSTEM_FILE_SEPERATOR
A holder for this clients System File Separator.
|
static String |
SYSTEM_LINE_SEPERATOR
A holder for this clients System line termination separator.
|
static String |
USERDIR
The users pwd ditrectory.
|
static String |
USERHOME
The users home ditrectory.
|
Constructor and Description |
---|
TomsCrypter()
Default constructor that gets all the basic class settimgs setup and gives you a class instance to do the work.
|
TomsCrypter(String fileName)
Constructor that gets all the basic class settimgs setup, setsup the filename to upload and gives you a class instance to do the work.
|
Modifier and Type | Method and Description |
---|---|
static long |
bzip2It(File fo)
Wrapper method to accept a dir or individual file in the passed in File
object AND then calls the method that writes the passed file/dir to this
MultiZip instances zip output stream.
|
static SecretKey |
decodeBase64ToAESKey(String encodedKey)
Takes a Base64 encoded string and creates an AES SecretKey from it.
|
String |
decrypt(String filename)
Alias for decryptFile using the default Pass.
|
String |
decrypt(String pass,
String filename)
Alias for decryptFile.
|
String |
decryptFile(String filename)
Decrypts the AES crypted file using the current class passwordKey and returns the decrypted filename.
|
String |
decryptFile(String pass,
String filename)
Decrypts the AES crypted file using the passed in passwordKey and returns the decrypted filename.
|
String |
decryptString(String encrypted) |
static String |
encodeAESKeyToBase64(SecretKey aesKey)
Serializes an AES SecretKkey to a Base64 encoded string.
|
String |
encrypt(String filename)
Alias for encryptFile using the default Pass.
|
String |
encrypt(String pass,
String filename)
Alias for encryptFile.
|
String |
encryptFile(String filename)
encrypts the file with AES using the current class passwordKey and returns the encrypted filename.
|
String |
encryptFile(String pass,
String filename)
encrypts the AES file using the passed in passwordKey and returns the encrypted filename.
|
String |
encryptString(String value)
Alias for encryptString using the default Pass.
|
static void |
ensureFolderExists(File folder)
recursively creates parent dirs and the requested dir
|
private String |
geteCryptPass()
get the eCryptPass password used for encryption.
|
String |
getEncryptFilemarker()
Returns the value of encryptFilemarker.
|
private String |
getloadFilePath()
get the filename path for the file that will be uploaded.
|
String |
jceDecryptString(String encrypted) |
String |
jceDecryptString(String key1,
String key2,
String encrypted) |
String |
jceEncryptString(String value) |
String |
jceEncryptString(String key1,
String key2,
String value) |
static void |
main(String[] args)
Syntax:
java ca.bc.webarts.tools.TomsCrypter [passwordKey] filename NOTE: if filename has the encrypted filemarker 'etbg' in its filename, then this will DEcrypt the passed in filename. |
static String |
printUsage()
Prints out the help syntax and usage details.
|
protected void |
seteCryptPass(String pass)
set the eCryptPass password used for encryption.
|
void |
setEncryptFilemarker(String encryptFilemarker)
Sets the value of encryptFilemarker_.
|
private void |
setloadFilePath(String path)
Set the filename path for the file that will be uploaded.
|
static long |
unBzip2It(File fo)
UnBzips the passed file (that must have a '.bz2' extension) to its same filename
in the same dir without the '.bz2' extension.
|
public static final String SYSTEM_FILE_SEPERATOR
public static final String SYSTEM_LINE_SEPERATOR
private static final String APPLICATION_NAME
private static final String DEFAULT_DOWNLOAD_DIR
private static final String DEFAULT_LOAD_FILENAME
private static final String DEFAULT_DATASTORE_DIR
private static final String ECRYPT_FILEMARKER_DEFAULT
private String loadFilePath_
private String dirForDownload_
private File dataStoreDir_
private String encryptFilemarker_
private String eCryptPass
public TomsCrypter() throws GeneralSecurityException, IOException
GDriveCrypter instance = new GDriveCrypter(); // uses the DEFAULT_LOAD_FILENAME //Authorize GDrive instance.initDrive(instance.authorize()); // Encrypt String encryptedFilename = instance.encrypt(instance.getloadFilePath()); if (encryptedFilename!=null && !encryptedFilename.equals("")) { // Send File to GDrive instance.setloadFilePath(encryptedFilename); File uploadedFile = instance.uploadFile(false); }
GeneralSecurityException
IOException
public TomsCrypter(String fileName) throws GeneralSecurityException, IOException
String fileNameToUpload = "someFile.txt"; TomsCrypter instance = new TomsCrypter(fileNameToUpload); instance.initDrive(instance.authorize()); // Encrypt String encryptedFilename = instance.encrypt(instance.getloadFilePath()); if (encryptedFilename!=null && !encryptedFilename.equals("")) { // Send File to GDrive instance.setloadFilePath(encryptedFilename); File uploadedFile = instance.uploadFile(false); }
GeneralSecurityException
IOException
public String getEncryptFilemarker()
public void setEncryptFilemarker(String encryptFilemarker)
encryptFilemarker
- The value to assign encryptFilemarker_.protected void seteCryptPass(String pass)
private String geteCryptPass()
private void setloadFilePath(String path)
private String getloadFilePath()
public static void ensureFolderExists(File folder)
public String encryptFile(String filename)
public String encryptFile(String pass, String filename)
public String encryptString(String value)
public String jceEncryptString(String value)
public String jceEncryptString(String key1, String key2, String value)
public String decryptString(String encrypted)
public String jceDecryptString(String encrypted)
public String jceDecryptString(String key1, String key2, String encrypted)
public static SecretKey decodeBase64ToAESKey(String encodedKey) throws IllegalArgumentException
IllegalArgumentException
public static String encodeAESKeyToBase64(SecretKey aesKey) throws IllegalArgumentException
IllegalArgumentException
public String decryptFile(String filename)
public String decryptFile(String pass, String filename)
public static long unBzip2It(File fo)
fo
- The File object to unzip - must have a '.bz2' extension.public static long bzip2It(File fo)
fo
- The File object to zip up (can be an actual file or dir).public static String printUsage()
public static void main(String[] args)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses