How to retrieve LDAP password via JNDI

后端 未结 2 786
误落风尘
误落风尘 2021-01-03 05:42

I am able to read the password stored in LDAP via JNDI. But the result is some gibberish characters. So how do i decrypt it?

Below is my code:

public         


        
相关标签:
2条回答
  • 2021-01-03 06:28

    with ldap we will get data in byte array.if you need to get the original password text use the
    following code:

    Attribute userPassword = attributes.get("userPassword");
    String pwd = new String((byte[]) userPassword.get());
    
    0 讨论(0)
  • 2021-01-03 06:48

    What you're seeing ([B@1cd8669) is Java's way of saying "this is a byte array".

    The stored "password" is most likely either a hash of the real password or an encrypted version. Cryptographic hashes are, by definition, non-reversible so you will not be able to see what the user's password is if LDAP stores the hash.

    If it's encrypted then if you know the algorithm and the key it's fairly simple to decrypt. BouncyCastle is a great Java crypto library you can use to decrypt the password.

    Basically, you need to know exactly what you're looking at, and that will depend on the LDAP setup.

    0 讨论(0)
提交回复
热议问题