从SubjectPublicKeyInfo获取公钥
我正在尝试从SubjectPublicKeyInfo 获取公钥。但是当我尝试时:
PublicKey publicKey = k.generatePublic(keypsec);
byte[] encoded=publicKey.getEncoded();
SubjectPublicKeyInfo subPkInfo2 = new SubjectPublicKeyInfo(rsaEncryption, encoded);
RSAPublicKeyStructure pubKey = new RSAPublicKeyStructure((ASN1Sequence)subPkInfo2.getPublicKey());
它会抛出此
java.lang.IllegalArgumentException: illegal object in getInstance: org.bouncycastle.asn1.DERSequence
at org.bouncycastle.asn1.DERInteger.getInstance(DERInteger.java:37)
at org.bouncycastle.asn1.x509.RSAPublicKeyStructure.<init>(RSAPublicKeyStructure.java:63)
任何想法吗?我尝试过 PubliKeyFactory 但它只是调用最后一行。
I'm trying to get the public key from a SubjectPublicKeyInfo.However when I try:
PublicKey publicKey = k.generatePublic(keypsec);
byte[] encoded=publicKey.getEncoded();
SubjectPublicKeyInfo subPkInfo2 = new SubjectPublicKeyInfo(rsaEncryption, encoded);
RSAPublicKeyStructure pubKey = new RSAPublicKeyStructure((ASN1Sequence)subPkInfo2.getPublicKey());
It throws this
java.lang.IllegalArgumentException: illegal object in getInstance: org.bouncycastle.asn1.DERSequence
at org.bouncycastle.asn1.DERInteger.getInstance(DERInteger.java:37)
at org.bouncycastle.asn1.x509.RSAPublicKeyStructure.<init>(RSAPublicKeyStructure.java:63)
Any ideas? I've tried PubliKeyFactory but it simply calls the last line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我将回答我自己的问题:
这是错误的。 PublicKey 已经是 ASN1typeSubjectpublicKeyInfo。为了使用此函数
SubjectPublicKeyInfo(AlgorithmIdentifier algId, byte[] publicKey)
创建SubjectPublicKeyInfo ,您需要一个 Algortihm 标识符和编码形式的密钥本身。 publicKey.getEncoded() 是一个编码的密钥+算法标识符。
反正。如果您想将 SATSA 公钥转换为主题公钥信息,请执行以下操作:
如果您想从主题公共密钥信息中获取作为 RSAkeyparameters 的公钥
Well I shall answer my own question:
This is wrong. PublicKey is already an ASN1typeSubjectpublicKeyInfo. In order to create a SubjectPublicKeyInfo with this function
SubjectPublicKeyInfo(AlgorithmIdentifier algId, byte[] publicKey)
you need an Algortihm identifier and THE KEY ITSELF in encoded form. publicKey.getEncoded() is an encoded KEY + THE ALGORITHM IDENTIFIER.
Anyway. If you want to tranfosrm a SATSA public key to a Subject Public Key Info you do this:
And if you want to get your public key as RSAkeyparameters from the SubjectPublicKeyInfo