HOME - WEBDESIGN / IPHONE APP - ALL IN VAIN - PICTURES - FORUM - DEVELOPEMENT - MYSPACE - TWITTER - YOUTUBE - CATEGORIES - Login/Registration - RSS

Countdown bis zum Greenfield 2011:


PL/SQL: How to convert MD5 from Hex to Base64


in Application Server,Code,Computer,Development @ 13:51 am 16. November 2009
Comments: 0

I was working with JBoss 5.1.0GA and I wanted to activate the JBoss MD5 Authentication. The passwords were stored as HEX 16Byte long (32 Hex Characters). When you have a look at the official JBoss User Manual (Chapter 9) you will see that they are using Base64-Encoding. So we had to come up with a short PL/SQL-script to convert the passwords to Base64!

Simply create a PL-SQL Script and add the following code:

[codesyntax lang="plsql"]

set sqlblanklines on;

set serveroutput on;

DECLARE

BEGIN

//read password field as hex-encoded raw data and convert data using base64 encoding

update users set password=utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(utl_raw.cast_to_varchar2(password))));

END;

[/codesyntax]

Additionally, if you have a unix or linux machine, you can check it in command line:

$ echo -n “j2ee” | openssl dgst -md5 -binary | openssl base64 glcikLhvxq1BwPBZN0EGMQ==

An Twitter senden, Geposted von Pädde


Java: How to get MD5 hash from password string


in Application Server,Code,Development @ 09:31 am
Comments: 0

Recently I had the problem that I had to convert a normal password string to a MD5 Password String which is Base64-Encoded. I found a lot of results but they just worked on JBoss 4.2, so I changed it and now it will also run on JBoss 5.1.0GA::

[codesyntax lang="java" strict="yes"]
package com.sicap.ssis2.servlets;
import java.security.MessageDigest;

/**
* @author doonot
*
*/
public class MD5HashGenerator {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String password = “testpassword”;
MessageDigest md = null;
try
{
md = MessageDigest.getInstance(“MD5″);
}
catch(Exception e)
{
e.printStackTrace();
}

byte[] passwordBytes = password.getBytes();
byte[] hash = md.digest(passwordBytes);
System.out.println(getHexString(hash));
String passwordHash = org.jboss.security.Base64Encoder.encode(hash);

System.out.println(“password hash: “+ passwordHash);
}

/**
* This method returns the hex string from the password byte array
* @param b Byte[]
* @return string hex password string
* @throws Exception
*/
public static String getHexString(byte[] b) throws Exception {
String result = “”;
for (int i=0; i < b.length; i++) {
result +=
Integer.toString( ( b[i] & 0xff ) + 0×100, 16).substring( 1 );
}
return result;
}
}

[/codesyntax]

Leave a short comment if you think that was usefull! Best regards!

An Twitter senden, Geposted von Pädde