Package com.zycus.dotproject.util

Source Code of com.zycus.dotproject.util.PasswordEncryptor

package com.zycus.dotproject.util;

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

import com.zycus.dotproject.exception.GenericException;

public final class PasswordEncryptor {
  private PasswordEncryptor() {
    throw new IllegalAccessError("this class should not be initialised");
  }

  @Override
  protected Object clone() throws CloneNotSupportedException {
    throw new CloneNotSupportedException("This class should not be cloned");
  }

  public static String getEncryptedPassword(String strPasswordToBeEncrypted) {
    System.out.println(strPasswordToBeEncrypted);
    byte[] defaultBytes = strPasswordToBeEncrypted.getBytes();
    try {
      MessageDigest algorithm = MessageDigest.getInstance("MD5");
      algorithm.reset();
      algorithm.update(defaultBytes);
      byte messageDigest[] = algorithm.digest();

      StringBuffer hexString = new StringBuffer();
      for (int iCounter = 0; iCounter < messageDigest.length; iCounter++) {
        hexString.append(Integer.toHexString(0xFF & messageDigest[iCounter]));
      }
      System.out.println(hexString.toString());
      return hexString.toString();
    } catch (NoSuchAlgorithmException nsae) {
      throw new GenericException("Problem while getEncryptedPassword", nsae, GenericException.Type.Normal);
    }
  }
}
TOP

Related Classes of com.zycus.dotproject.util.PasswordEncryptor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.