This discussion is archived
1 Reply Latest reply: Oct 9, 2011 1:36 PM by EJP RSS

problems with SHA

730895 Newbie
Currently Being Moderated
Hello all!
I am using eclipse and google app engine.
I am trying to use SHA for my password for web application.
I have an error on this line:
 String hash = (new BASE64Encoder()).encode(raw); //step 5 
the errors are:
java.lang.NoClassDefFoundError: sun.misc.BASE64Encoder is a restricted class. Please see the Google  App Engine developer's guide for more details.
     at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
     at login.PasswordService.encrypt(PasswordService.java:38)
my full code is:
package login;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
//import org.myorg.SystemUnavailableException;
import sun.misc.BASE64Encoder;
import sun.misc.CharacterEncoder;
 
public final class PasswordService
{
  private static PasswordService instance;
 
  public PasswordService()
  {
  }
 
  public synchronized String encrypt(String plaintext) throws Exception
  {
    MessageDigest md = null;
    try
    {
      md = MessageDigest.getInstance("SHA"); //step 2
    }
    catch(NoSuchAlgorithmException e)
    {
      throw new Exception(e.getMessage());
    }
    try
    {
      md.update(plaintext.getBytes("UTF-8")); //step 3
    }
    catch(UnsupportedEncodingException e)
    {
      throw new Exception(e.getMessage());
    }
 
    byte raw[] = md.digest(); //step 4
    String hash = (new BASE64Encoder()).encode(raw); //step 5
    return hash; //step 6
  }
 
  public static synchronized PasswordService getInstance() //step 1
  {
    if(instance == null)
    {
       instance = new PasswordService();
    }
    return instance;
  }
}
thanks for help
  • 1. Re: problems with SHA
    EJP Guru
    Currently Being Moderated
    Please see the Google  App Engine developer's guide for more details.
    When you did that, what part of what you read there didn't you understand?

    This is only one error, not 'errors', and it has nothing to do with SHA.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points