【问题标题】:JNDI LDAP How to decode SSHA passwordJNDI LDAP 如何解码 SSHA 密码
【发布时间】:2014-09-18 08:58:04
【问题描述】:

我使用 apacheds(作为 LDAP 服务器)并使用 apache directory studio 将条目插入其中。对于 userPassword 属性,我只选择了纯文本。但是,apache directory studio 正在对其进行加密。我不知道这是为什么。现在,我检索该条目的 java 程序给了我一个 ssha 加密密码。有谁能帮我解码它吗?

    import java.util.Hashtable;
    import javax.naming.Context;
    import javax.naming.NamingEnumeration;
    import javax.naming.NamingException;
    import javax.naming.directory.Attribute;
    import javax.naming.directory.Attributes;
    import javax.naming.directory.DirContext;
    import javax.naming.directory.InitialDirContext;

    class GetAttrs {
    public static void main(String[] args) {

    // Set up the environment for creating the initial context
    Hashtable<String, Object> env = new Hashtable<String, Object>(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY,
      "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://localhost:10389/o=mojo");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
    env.put(Context.SECURITY_CREDENTIALS, "secret");

    try {
    // Create initial context
    DirContext ctx = new InitialDirContext(env);

    // Specify the ids of the attributes to return
    String[] attrIDs = { "cn", "sn", "uid", "userPassword" };

    // Get the attributes requested
    Attributes answer = ctx
      .getAttributes("cn=Harish Koppala, ou=Users", attrIDs);

    // Print the answer
    printAttrs(answer);

    // Close the context when we're done
    ctx.close();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    static void printAttrs(Attributes attrs) throws Exception{
    if (attrs == null) {
    System.out.println("No attributes");
    } else {
    /* Print each attribute */
    try {
    for (NamingEnumeration ae = attrs.getAll(); ae.hasMore();) {
      Attribute attr = (Attribute) ae.next();
      System.out.print(attr.getID()+" : ");
      /* print each value */
      if("userpassword".equalsIgnoreCase(attr.getID())){
          for (
                  NamingEnumeration e = attr.getAll();
                  e.hasMore();                    
                  System.out.println(new String((byte[])e.next()))
               );
      }else{
      for (
              NamingEnumeration e = attr.getAll();
              e.hasMore();
              System.out.println(e.next())
          );
      }
      }
     } catch (NamingException e) {
     e.printStackTrace();
     }
     }
     }

     }

输出:
用户密码:{SSHA}SKA8QY7BBX0tgdZlzL+3sEDFnIBsJwd8VHjexw==
uid:hwilliams
sn : 威廉姆斯
cn : 雨果·威廉姆斯

【问题讨论】:

    标签: java ldap jndi apacheds


    【解决方案1】:

    它没有加密它。它正在安全地散列它。您无法解密或解码它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-22
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多