The Antimatter library includes an eclectic set of generally reusable classes. The classes are not tied to any particular framework and dependencies on other non-core Java classes have been minimized.
The Encrypter class provides for the encryption and decryption of text strings using the robust and well-supported encryption algorithms supported by JCE (Java Cryptographic Extensions), an implementation of the JCA (Java Cryptography Architecture). The JCE is included with the Java JDK, and should thus be readily available within most development environments. Encrypted text can be binary and is thus further encoded in base64 for easy transport as strings.
The Encrypter class should meet most encryption/decryption needs, but has not particularly been designed with speed in mind. It is ideal for encrypting vital fields, such as passwords stored in configuration files or in a database.
The following code provides an example of how to use the class to first encrypt and then decrypt a string (the word "clarke" in the example below). The "A345B2Nu" string is a secret key string, which is used in the encryption/decryption algorithms.
String strContent = "clarke";
// Encrypt the string using the DES algorithm, with the key provided
Encrypter objEncrypter = new Encrypter("A345B2Nu", "DES");
String strEncrypted = objEncrypter.encrypt(strContent);
// Now create another Encrypter instance and decrypt the string
Encrypter objEncrypter2 = new Encrypter("A345B2Nu", "DES");
String strDecrypted = objEncrypter2.decrypt(strEncrypted);
Note that the standard encryption/decryption code examples available on the web depend on the Base64 encoding/decoding functionality provided by the sun.misc.Base64Encoder and sun.misc.Base64Decoder classes. These are unsupported classes; they are also not guaranteed to work on other platforms. Accordingly, the Encrypter class uses the base64 functionality provided by the Apache commons-codec class.
BasicDataSource: The BasicDataSource class represents a data source, generally a relational database, from which data may be retrieved once a connection has been established. It is essentialy a thin wrapper around the standard Java Connection class.
BasicConnection: This class inherits from BasicDataSource but adds more interesting functionality. It includes support for reading database connection settings from a property file. It also supports property files with both plain-text and encrypted passwords, with the latter being preferred.
Database: This class provides generic support for interrogating a relational database for information such as: 1) the list of tables, or 2) the list of columns within a table. It currently works with MySQL and Oracle, although it could be adpated for other databases relatively easily.
The Resource class provides basic capabilities for accessing resource files stored within a Jar file or within the class directory hierarchy. For example, an application can have a properties file with default settings stored within a Jar file, a technique that seems generally better than embedding default settings within code.