将公钥/私钥字符串转换为 RSA xmlstring
我的伙伴给了我一个RSA公钥,看起来像这样:
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCSK+roLfbUYf6PGNIf6Ej8R5EqSTjlRABTu7T0FxR/B6iurI80jktW9+zKu4jFnFJ8oYx24raD3x5KhJZR2VCBEEbtYpPq/5E25v+LIkFbx8sNkMvEACZdAWyeQcEookGfKDER4PGrB35bntcO2SnItTZc8BOI3jAOBXTeBO16NwIDAQAB
我知道公钥中有模数和指数,我见过一个xml RSA密钥文件;但我不知道如何从这个普通字符串中提取这些部分。
有人知道如何完成我想做的事情吗?
My partner gave me an RSA public key that looks like this:
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCSK+roLfbUYf6PGNIf6Ej8R5EqSTjlRABTu7T0FxR/B6iurI80jktW9+zKu4jFnFJ8oYx24raD3x5KhJZR2VCBEEbtYpPq/5E25v+LIkFbx8sNkMvEACZdAWyeQcEookGfKDER4PGrB35bntcO2SnItTZc8BOI3jAOBXTeBO16NwIDAQAB
I know that there are Modulus and Exponent in a public key, I've seen an xml RSA key file; but i don't know how to extract those parts from this plain string.
Would anyone know how to accomplish what I am trying to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个base-64编码的SubjectPublicKeyInfo(参见RFC 5280), RSA 公钥。正如您所指出的,它包含 RSA 模数和公共指数。
That is a base-64 encoded SubjectPublicKeyInfo (see RFC 5280), for an RSA public key. It contains, as you noted, an RSA modulus and public exponent.
为了完成GregS的答案,假设您使用Java作为编程语言:
SubjectPublicKeyInfo
ASN.1 结构解码二进制 blob。这不是很容易(除非您掌握 ASN.1),但可以使用现有代码。特别是,Java 知道如何直接做到这一点。Java 中的公钥解码如下所示(假设二进制 blob 位于变量
blob
中):并且从
RSAPublicKey
实例中,您可以获取getModulus() 和 getPublicExponent()
方法是不言自明的。相关类位于包java.security
、java.security.interfaces
和java.security.spec
中。对于您的公钥,这会产生以下结果:To complete the answer of GregS, assuming that you use Java as a programming language:
SubjectPublicKeyInfo
ASN.1 structure. This is not very easy (unless you master ASN.1) but existing code can be used for that. In particular, Java knows how to do that directly.Public key decoding in Java looks like this (assuming the binary blob is in variable
blob
):and from the
RSAPublicKey
instance, you have thegetModulus()
andgetPublicExponent()
methods which are self-explanatory. The relevant classes are in packagesjava.security
,java.security.interfaces
andjava.security.spec
. For your public key, this yields the following: