Package org.groovymud.shell.security

Source Code of org.groovymud.shell.security.PasswordService

package org.groovymud.shell.security;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import com.thoughtworks.xstream.core.util.Base64Encoder;

/**
*
* performs encrypt operations on passwords
*
* @author matt
*
*/
public class PasswordService {

  public synchronized String encrypt(String plaintext) throws PasswordException {
    MessageDigest md = null;
    try {
      md = MessageDigest.getInstance("SHA"); // step 2
    } catch (NoSuchAlgorithmException e) {
      throw new PasswordException(e.getMessage());
    }
    try {
      md.update(plaintext.getBytes("UTF-8")); // step 3
    } catch (UnsupportedEncodingException e) {
      throw new PasswordException(e.getMessage());
    }
    byte raw[] = md.digest(); // step 4
    String hash = (new Base64Encoder()).encode(raw); // step 5
    return hash; // step 6
  }
}
TOP

Related Classes of org.groovymud.shell.security.PasswordService

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.