I’ve been dealing with some java application that connect to multiple databases. All the database information are stored in properties file. This includes the password as well. I stumbled upon the Cryptix.
I’m able to encrypt and decrypt using several lines of code as follow:
byte[] bytes = passwordString.getBytes(i);
Security.addProvider(new Cryptix());
RawSecretKey key = null;
key = new RawSecretKey("Blowfish","Holly's secret key to unlock".getBytes());
Cipher cipher = Cipher.getInstance("Blowfish", "Cryptix");
cipher = Cipher.getInstance(cipher, null , new PKCS7());
cipher.initDecrypt(key);
System.out.println(new String(cipher.crypt(bytes)));
To learn more about Cryptix, you can read this FAQ.
JAVA: Encrypt Your Password
Bash: Send HTML Email from Linux Command Line
I’m trying to send an HTML formatted email from Linux Command line. Previously, I use mailx to send the email, but it’s only allow us to send plain text email. Luckily, I came across to ‘sendmail’. After testing couple of time, I’m finally able to send HTML formatted email. The code as follow:
(cat <<EOCAT
Subject: Title of the email
MIME-Version: 1.0
Content-Type: text/html
Content-Disposition: inline
EOCAT
cat htmlfile.html) | sendmail toemail@hollyghozi.com
As you see in my code above, there’re two parts of the email that I combine into one and send using ‘sendmail’.
- Header: the first ‘cat’
- Body: the second ‘cat’ is reading ordinary HTML file
and both redirect to sendmail that will send an HTML to recipient.
PHJDBC: Temporary Remove the Java System Output
When I execute SQL query using PowerHub JDBC driver, it always gives connection status.
Connecting to //powerhubmachine/pe_dic-server
Connected to ////powerhubmachine/pe_dic-server (PowerHub 20.0)
To remove this output, I temporarily redirect the output to ‘null’, as shown in snippet below:
private void connect() throws IOException
{
try {
PrintStream oriOut = System.out;
System.setOut(new PrintStream(new OutputStream(){public void write (int b){}}));
Class.forName("com.lgc.dam.phs.client.jdbc.PhsJDBCDriver");
if (connurl!=null) {
conn = DriverManager.getConnection(connurl);
} else {
conn = DriverManager.getConnection("jdbc:scwapi://"+phserver+"/"+pedic+"-"+rmiserver+";"+username+";"+password+";SYSTEM;SYSTEM");
}
System.setOut(oriOut);
} catch (Exception e) {
System.out.println(e.toString());
}
}
Using the ‘setOut’ to newly create empty OutputStream, it hides the output. After finish, ‘setOut’ to original OuputStream.



