Package l2p.loginserver.crypt

Source Code of l2p.loginserver.crypt.Whirlpool

package l2p.loginserver.crypt;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Logger;

import jonelo.jacksum.JacksumAPI;
import jonelo.jacksum.algorithm.AbstractChecksum;

public class Whirlpool implements Crypt
{
  protected static Logger _log = Logger.getLogger(Whirlpool.class.getName());
  private static Whirlpool _instance = new Whirlpool();

  public static Whirlpool getInstance()
  {
    return _instance;
  }

  @Override
  public boolean compare(String password, String expected)
  {
    try
    {
      return encrypt(password).equals(expected);
    }
    catch(NoSuchAlgorithmException nsee)
    {
      _log.warning("Could not check password, algorithm Whirlpool not found! Check jacksum library!");
      return false;
    }
    catch(UnsupportedEncodingException uee)
    {
      _log.warning("Could not check password, UTF-8 is not supported!");
      return false;
    }
  }

  @Override
  public String encrypt(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException
  {
    AbstractChecksum whirlpool2 = JacksumAPI.getChecksumInstance("whirlpool2");
    whirlpool2.setEncoding("BASE64");
    whirlpool2.update(password.getBytes("UTF-8"));
    return whirlpool2.format("#CHECKSUM");
  }
}
TOP

Related Classes of l2p.loginserver.crypt.Whirlpool

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.