com.skilrock.lms.common.utility.MD5Encoder.java Source code

Java tutorial

Introduction

Here is the source code for com.skilrock.lms.common.utility.MD5Encoder.java

Source

/*
 *  copyright 2007, SkilRock Technologies, A division of Sugal & Damani Lottery Agency Pvt. Ltd.
 * All Rights Reserved
 * The contents of this file are the property of Sugal & Damani Lottery Agency Pvt. Ltd.
 * and are subject to a License agreement with Sugal & Damani Lottery Agency Pvt. Ltd.; you may
 * not use this file except in compliance with that License.  You may obtain a
 * copy of that license from:
 * Legal Department
 * Sugal & Damani Lottery Agency Pvt. Ltd.
 * 6/35,WEA, Karol Bagh,
 * New Delhi
 * India - 110005
 * This software is distributed under the License and is provided on an AS IS
 * basis, without warranty of any kind, either express or implied, unless
 * otherwise provided in the License.  See the License for governing rights and
 * limitations under the License.
 */

package com.skilrock.lms.common.utility;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import sun.misc.BASE64Encoder;

public class MD5Encoder {
    static Log logger = LogFactory.getLog(MD5Encoder.class);

    public static String encode(String value) {

        try {

            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] hashMD5 = md5.digest(value.getBytes());
            return (new BASE64Encoder()).encode(hashMD5);

        } catch (NoSuchAlgorithmException e) {

            e.printStackTrace();
        }

        return null;
    }

}