String key = "just a bunch of text"; byte[] bytes = new byte[256]; byte[] kbytes = key.getBytes(); for (int i = 0; i < bytes.length; i++) { if (i < kbytes.length) { bytes[i] = kbytes[i]; } else { bytes[i] = (byte) i; } } byte[] md5digest = md5DigestAsBytes(bytes); try { theGeneratedKey = Twofish_Algorithm.makeKey(md5digest); blockSize = Twofish_Algorithm.blockSize(); catch (java.security.InvalidKeyException ike) { throw new Exception(Exception.E_SECURITY, "Invalid security key '" + new String(md5digest) + "'", ike); }