public static void main(String[] args)
    throws IOException
  {
    String algorithm = (args.length >= 1 ? args[0] : ALGORITHM).toUpperCase();
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    MessageDigest md = null;
    String prefix = null;
    String plaintext;    try
    {
      md = MessageDigest.getInstance(algorithm);
    }
    catch (NoSuchAlgorithmException e)
    {
      // ignore
    }    if (md == null)
    {
      System.err.println("Error: unknown algorithm \"" + algorithm + "\"");
      System.exit(1);
    }
      
    System.err.println("Enter plaintext passwords, separated by newlines.");
    
    while ((plaintext = r.readLine()) != null)
    {
      String passwd = "{" + algorithm + "}" + hash(md, plaintext);
      
      System.out.println(passwd);      if (System.out.checkError())
      {
throw new IOException("output error");
      }
    }    r.close();
  }
}From weblogic.examples.security.rdbmsrealm.RDBMSUser

解决方案 »

  1.   

    <%@page import="java.security.MessageDigest" %>
    <%@page import="weblogic.utils.encoders.BASE64Encoder" %>
    <%
        MessageDigest md = null;
        String algorithm="SHA";
        String plaintext="your old password";
        String passwd="";
        md = MessageDigest.getInstance(algorithm);
        BASE64Encoder enc = new BASE64Encoder();
        passwd=enc.encodeBuffer(md.digest(plaintext.getBytes()));
    %>
    <html>
    <head>
    <title>
    sha code
    </title>
    </head>
    <body>
    this is the old passwd: <%=plaintext%>
    <br>
    this is the new passwd after encode:<%=passwd%>
    <br>
    </body>
    </html>