Welcome to my website. I am always posting links to photo albums, art, technology and other creations. Everything that you will see on my numerous personal sites is powered by the formVistaTM Website Management Engine.


  • Subscribe to this RSS Feed
  • Resources for Understanding Object-Oriented JavaScript
    02/20/2012 3:12PM
  • JavaScript Resources
    02/20/2012 3:07PM
  • ECMAScript 5 Compatibility Table
    02/20/2012 2:16PM

    Very handy ECMAScript 5 compatibility table for the JavaScript programmer:


  • Creating a MD5 Hash in Java From Either a String or the Byte Value of a Long
    02/07/2012 11:53AM

    Following is a quick example of how to generate an MD5 Hash (SHA-256, SHA-512 or any other supported hash algorithm) of either a String or the byte value of a long.  You should be able to adapt for your particular application:

    package com.ryanchapin.util;

    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.io.UnsupportedEncodingException;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;

    public class HashGenerator {

        public static String createHash(long input, String hashAlgorithm) {
            // Generate a byte array from the long
            // Extract the byte value of the long
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);

            try {
            } catch (IOException e) {
            try {
            } catch (IOException e) {

            byte[] byteArray = bos.toByteArray();
            return bytesToHex(computeHashBytes(byteArray, hashAlgorithm));

        public static String createHash(String input, String hashAlgorithm) {
            // Generate a byte array from the input String.
            byte[] inByteArray = null;
            try {
                inByteArray = input.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {

            return bytesToHex(computeHashBytes(inByteArray, hashAlgorithm));

        private static byte[] computeHashBytes(byte[] inputBytes, String hashAlgorithm) {
            // Instantiate a MessageDigest instance configured with the desired
            // algorithm.
            MessageDigest md = null;
            try {
                md = MessageDigest.getInstance(hashAlgorithm);
            } catch(NoSuchAlgorithmException e) {

            // This isn't necessary in this context, but should this
            // be refactored to use the MessageDigest as a member this
            // enables the reuse of the same MessageDigest instance.
            return md.digest();

        private static String bytesToHex(byte[] hashBytes) {

            // Convert the hashBytes to a String of hex values
            StringBuilder retVal   = new StringBuilder();
            StringBuilder hexValue = new StringBuilder();

            for (byte hashByte : hashBytes) {
                // Flush our StringBuilder to be used as a container for the
                // hex value for each byte as it is read.
                hexValue.delete(0, hexValue.length());
                hexValue.append(Integer.toHexString(0xFF & hashByte));

                // Add a trailing '0' if our hexValue is only 1 char long
                if (hexValue.length() == 1) {
                    hexValue.insert(0, '0');
            return retVal.toString();

        public static void main(String[] args) {

            // Hash using MD5
            System.out.println(createHash("12345", "MD5"));
            System.out.println(createHash(12345L, "MD5"));

            // Hash using SHA-256
            System.out.println(createHash("12345", "SHA-256"));
            System.out.println(createHash(12345L, "SHA-256"));

  • Great PL/SQL Overview and Tutorial
    02/01/2012 1:37PM
Advanced Search