Question

In LDAP server, i stored my public key in string format. I have to compare the value retrieved from LDAP server and user certificate's public key.

From LDAP, I am retrieving "public key" in string format. By the following method I am getting the output in Publickey format.

   PublicKey pub = certificate.getPublicKey();

For example:

 public key which store and retrieved from ldap : 3082010a0282010100da7ce03ec4628dce29042f93787c6a70c0ee2c2911696519c2e2ca10526ae7c97c8b6f095c    755f8c5e9c6ab97937bc6b70cdda8791ecd4c23b53cc5a981ea4be54d849926812d54e1f0c1d8d209f1966a29d27    b3b38831fbbf4aa80cb942f419e82dbb7bdc43790edfe39093697b89f8c306825307a674e7ead0a9a204a7c4331b    bd91bb95450ad2b978e635754d93a463220951c0f686e745ab56f1546a97ae2d87f530bde91cd50c2227d8dc15dcfa83b5f8bfd9e0b220bd8c1aa79763eb9ba7fd7825068febc0eb5bcfaafb87f3cfd17e2cbbe2f34ca38afe41f4bbc2042fa60dcf523601c8e5814c9aa6b59a122f27bd8b41645d9e4d6354e6e73290a44b0203010001

By the getPublicKey(), the values which i got from the certificate:

***
Sun RSA public key, 2048 bits
  modulus: 27581529112434455235399395495614661533524412849635912113821287924504314523203618221111108554792991994769511573234800381771189010092150662628156212797633901233021643754113925752858789999673304383861033906601469425706410753965248401239420679412397865844085987446528705248999902851200983500329050023325120622391550261964890287105642353902616488504197743500423303718260297874452584758316112606373795219655154047474828562736482689611898639008146126941813294363625955891232168718045290340674469984492628450581693408065679439269743483807803383534881136917173883224245178115070348015851631285800664873321494327268193971774539
  public exponent: 65537

  System.out.println("the encoded thing is...."+pub.getEncoded()) is: [B@2c683bfc

  BASE64Encoder encoder = new BASE64Encoder();
  String s = encoder.encode(pub.getEncoded());
   o/p is
      MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2nzgPsRijc4pBC+TeHxqcMDuLCkRaWUZ    wuLKEFJq58l8i28JXHVfjF6carl5N7xrcM3ah5Hs1MI7U8xamB6kvlTYSZJoEtVOHwwdjSCfGWai      nSezs4gx+79KqAy5QvQZ6C27e9xDeQ7f45CTaXuJ+MMGglMHpnTn6tCpogSnxDMbvZG7lUUK0rl4     5jV1TZOkYyIJUcD2hudFq1bxVGqXri2H9TC96RzVDCIn2NwV3PqDtfi/2eCyIL2MGqeXY+ubp/14JQaP68DrW8+q+4fzz9F+LLvi80yjiv5B9LvCBC+mDc9SNgHI5YFMmqa1mhIvJ72LQWRdnk1jVObnMpCkSwIDAQAB

Is there any way to compare both the values? String and Publickey

Was it helpful?

Solution 3

In ldap we can directly save our certificate instead of storing as integer values.

  In ldif file:
    dc: xxxx
    objectClass: yyyyy
    userCertificate;binary:< file:///path/to/certificate.der

like this we have to upload..:)

package to handle certificates:

 java.security.cert.X509Certificate 

OTHER TIPS

i am storing the public key in the "string" format in LDAP server.

That's your first mistake. Don't do that. Store it as a byte array. String is not a container for binary data.

After that it's just a matter of comparing byte arrays, which you can do via Arrays.equals().

If the string that you got from LDAP server is of Base64encoded,

Encode you Public key object to String


1. Convert it to Byte array.

    byte array = pub.getEncoded();

2. Convert Byte array to String.

    BASE64Encoder encoder = new BASE64Encoder();
    string = encoder.encode(byte array);

Now you can compare the strings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top