gpt4 book ai didi

java - 在java中将字符串转换为java.Security.Publickey

转载 作者:太空宇宙 更新时间:2023-11-04 07:09:24 28 4
gpt4 key购买 nike

在 LDAP 服务器中,我以字符串格式存储了我的公钥。我必须比较从 LDAP 服务器检索到的值和用户证书的公钥。

我正在从 LDAP 检索字符串格式的“公钥”。通过以下方法,我得到了公钥格式的输出。

   PublicKey pub = certificate.getPublicKey();

例如:

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

通过getPublicKey(),我从证书中获得的值:

***
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

有什么方法可以比较这两个值吗?字符串和公钥

最佳答案

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

这是你犯的第一个错误。不要那样做。将其存储为字节数组。字符串不是二进制数据的容器。

之后,只需比较字节数组即可,您可以通过 Arrays.equals() 来完成。

关于java - 在java中将字符串转换为java.Security.Publickey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20877645/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com