1 Reply Latest reply on Apr 7, 2003 1:10 PM by Jonathan Leech

    sha1 hashing

    amirbekyan Newbie

      could somebody give me a clue to how to have sha1 hashing for user passwords stored in a DB. Has jboss some module that implements the sha1?

        • 1. Re: sha1 hashing
          Jonathan Leech Newbie

          Java has a SHA implementation, but typically if you see a SHA'd password (e.g. in LDAP) it is shown Mime-encoded. The netscape LDAP api has a mime-encoder-decoder in it. Here is how I do it:

          import netscape.ldap.util.ByteBuf;
          import netscape.ldap.util.MimeBase64Decoder;
          import netscape.ldap.util.MimeBase64Encoder;

          public static String SHA(String data)
          throws LDAPException
          {
          MessageDigest md;
          try {
          md = MessageDigest.getInstance("SHA");
          }
          catch (java.security.NoSuchAlgorithmException nsae) {
          nsae.printStackTrace();
          throw new Exception("SHA algorithm not found.");
          }
          MimeBase64Encoder me = new MimeBase64Encoder();
          md.reset();
          md.update(data.getBytes());
          byte[] bytes = md.digest();
          ByteBuf bbin = new ByteBuf(bytes, 0, bytes.length);
          ByteBuf bbout = new ByteBuf();
          me.translate(bbin, bbout);
          return "{SHA}" + bbout.toString();
          }