我正在尝试使用标准的目标 c 函数生成 RSA 密钥对:SecKeyGeneratePair。
一切正常,我可以将此密钥导出到某个文件,但此密钥无法使用。当我导入 C# 应用程序时,我收到“错误数据”错误。
如果我更深入地研究这个键(例如使用http://lapo.it/asn1js/),我可以看到素数“P”比使用不同工具生成的任何键都大。这个数字有 1025 位,而不是超过 1024...
生成的密钥:
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAw7plSEd4ZCK8O8n+z4wePDhR4VaKhl1ynOy4YJNTbpbBjSbV
sbr+wU8GqnkTj/NSjw0ypRWxognEZkt/SkLDrZ3dCgeLyuLntEMAZ2azWyrnsJWy
jBYhJ3nh3ZwW9K/0gQa5qOaWjstFuCLSHYiQktgFfjx4JpLCgpKkhEr8xBhnEJWn
kUwGbxRdWpeWcIiz7DFmqRKQ1cf+8WlkAuxVAcslhxDZaC/+OLCkrlFpMjRt2Dks
FYsaqBmKfeU8Oq00/m5ZBUwoKR9S1l/KTxtSQgvMAENs7XtwA9+LGZR6RXc1/7hk
GYL38ATmSA5YLXRTxg98n0prvgYj23nK5SYIyQIDAQABAoIBAFIRGpyG0xTxd4l+
NagicR8A4lwgZC7YidEAdIKR416wOXGMwfcml+DH2Nyrraci+A/hEcYkZXmyrLXT
nAiwG8n1MhQde+DS6SItIcM5TaTBRapF6jpQoRAjS7AW3Y01Jcjf4ALQxHoVAyOk
/gLCGxRnHU6D3kEWMhZ7lB2gL4Gscxe/G01piioPZfuzBGAUS+btsfGnPJdtNQJz
M9cX3FR00r4aBTYUndL90orQClkNrxqrGRCjZ3ThG+mAgUPx7X0FZvG6eUATIjFl
AhQfOSeLFRJXFj8VqffffbDDcW6yWP1png5r3ltfo4F/VZJ1pZIyruts5+RQq7YT
XTvyCs0CgYEBpZa8d0KChXv1fEaVjDA+db/s/5bDdb46bq5vTCNCNE772iN31dkI
/PGXisSgrTmyrwugZ1T5THPmMDDlBPu8JSACPlzgg31PWvQ4S429dsd/kbrxMq5u
rZQ2gRDjGVg32CJErV+UzHJ97g1HST4IkSTaIlqTHTLzfRTkairFbIcCgYB22fF0
+2PSPyK3ktRX5psgVyAgYt+1rc5+T/++2GQyRBEL4ZU86KeduBaZeUaOVGuSPu7C
doBYlYy3OWesp1/fzDXKfaCT/9TnRIgSY1XaJg6Qnma6HnGnTWjfjLiM3rdfImB/
2Bsyeak5+QjbqSf05sLFgZlcj+S2iCLjW2MELwKBgQC8YRJtp8ZypuUWVuPT9Gq0
asIXouJL5mhttHv+5XJbtT9MRbTyVTxy6fDxDNNPFA0HsoZGJe4Pf2pH9lEfXOzB
GgBmpVGc741Z8u6EtB0IyjPyhjnoj5Dc9vEz0rvnQ0gQx58waRkwEai7iitkStfB
I1plJ1u9HFs4dPFrjxkQWQKBgEHGkFj7n90F0ALkodwb5hJZ5Y/G6KQ1kqhZQeKv
A5TGEuEOcXeKEum4rdk2QxQWKIqBhcXdq15bNctZW8UzxF2pOMPeDvaZiYyMYvo6
O5NFqJ3k7Flo6+F5d+bwjFp6D+X4sotOYI7owf0xk/NthI2HAJgqB2QwxpU2doh5
VS1FAoGBAWw6lShxyuMwFIzD6EmOnX+HjYLlDTeVNy7pv/Vm7DtSIPsY2dg/iqU/
uCXsjQf5U1chYeE3hFUbPAGGbTxIL7/m6Y+ZjoKBywjSB9favG9BfQmjpRBBjmPO
cdPbTs9imzSaavoTPinJ/PeiqrfrW0tPKA049qP/X8xQrQe2erKp
-----END RSA PRIVATE KEY-----
还有其他方法可以生成此密钥吗?
- - - -编辑 - - - - - - - - - -
我生成了新密钥:
-----开始 RSA 私钥-----
MIIEowIBAAKCAQEAvMkeQSIYKof9baN+ZMvtlhkcJdiQvyoVJwEST285/9h+CB4c
2/6gCp9/OvsWAADqLGA9R/XxUjezkC28efoLguiSmO8b+1BLB+05eE8V7dwJT2zG
lHrGzjcN+ZhqO3uHRhVcckUWXygb+YZl02mtSidXr9PmlI53pECJTgmM6wZOu1Df
CU1nCyLwN9zomkTAfkp7UX2pMJBARVod73FFILaRxJXN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SPzOWKceG7B+rYI/lSbE/PG2kz5w40zIQKJVzhLHt2PFwHKDcxuR0FAsfJjzr
Bx4pJs/mBeBs8izcvrAouKoQTmcalYntnezV3F73IVBzVnwR06DYvPyLo4nryXx0
bLlZAoGBATNu+VCOU+y5tXNN8rwGBZO+fjAidgVXwo24DxFUdXIWZUT7DvXz+1HH
B900fBkQWXGPaDQhmqtz5eJUOlgUIlTqRo7tWivQcioq8xdvk3LA81GhGxeDpSAU
W59OGqm3ApaKnZla0B3nQ9AxdAzqf5x5SOhL9PqBbVuTRm49BIj8
-----END RSA PRIVATE KEY-----
这是 iPhone 导出的公钥:
-----BEGIN RSA PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvMkeQSIYKof9baN+ZMvt
lhkcJdiQvyoVJwEST285/9h+CB4c2/6gCp9/OvsWAADqLGA9R/XxUjezkC28efoL
guiSmO8b+1BLB+05eE8V7dwJT2zGlHrGzjcN+ZhqO3uHRhVcckUWXygb+YZl02mt
SidXr9PmlI53pECJTgmM6wZOu1DfCU1nCyLwN9zomkTAfkp7UX2pMJBARVod73FF
ILaRxJXNX6/61jMrVuTlGXLshDgrBsfgHd9D4rnfMZtIn7DTUSit+Za0zmvJDKKt
XSNYdGO82UnSUv+IlyzVcCNH+uPenSEPMqrHi83fi/aX/SwwdD+yA+jv4n2cfm75
zwIDAQAB
-----END RSA PUBLIC KEY-----
而这里 C# 导出的公钥:
-----BEGIN RSA PUBLIC KEY-----
MIIBITANBgkqhkiG9w0BAQEFAAOCAQ4AMIIBCQKCAQC8yR5BIhgqh/1to35ky+2W
GRwl2JC/KhUnARJPbzn/2H4IHhzb/qAKn386+xYAAOosYD1H9fFSN7OQLbx5+guC
6JKY7xv7UEsH7Tl4TxXt3AlPbMaUesbONw35mGo7e4dGFVxyRRZfKBv5hmXTaa1K
J1ev0+aUjnekQIlOCYzrBk67UN8JTWcLIvA33OiaRMB+SntRfakwkEBFWh3vcUUg
tpHElc1fr/rWMytW5OUZcuyEOCsGx+Ad30Piud8xm0ifsNNRKK35lrTOa8kMoq1d
I1h0Y7zZSdJS/4iXLNVwI0f6496dIQ8yqseLzd+L9pf9LDB0P7ID6O/ifZx+bvnP
AgMBAAE=
-----END RSA PUBLIC KEY-----
要将密钥导入 C#,我使用 BouncyCastle 库:
Org.BouncyCastle.OpenSsl.PemReader pemReader = new PemReader(File.OpenText("C:\\Users\\pawel_000\\Documents\\Tmp\\mBankFasada\\klucze4\\private2048.pem"));
RsaPrivateCrtKeyParameters bckey = (RsaPrivateCrtKeyParameters)((AsymmetricCipherKeyPair)pemReader.ReadObject()).Private;
RSAParameters key = DotNetUtilities.ToRSAParameters(bckey);
在 iPhone 中,我签署了以下字符串:607767767
并且签名结果是(在base64中,哈希:SHA512):
SQ3FqzCko8t3oL14czjjEkRgRVO4Z8F5135MFvJNKcN6w/JPYLxtWQicHQi5N
p72uNAh4Xy3g/EVukme1bZScE4prng0huZY/aWv2jUUhgRtNYrExlY6ScHkh+
asUgj8jThGB2CPQq1qSOroCcFeRAoGk7f4JPZnuZkvvgnTIPu72OrsuGhWH
AE5SFF+Z0MGbtdKM1mhK6PMeAEHBm2Iu0axN3G9IWoLF613dzHPPK6wrkkd8
8mGqrzlw/Pwo6d9IzSdHWnteGBUaOvx2EH5MQiMhJtiAnbhBtPLrmYn2bxP9
bsg3ymYW4gdmOtMgLRaheoaxBfgZ6Hrl5BAtwO7BA==
我可以为 C# 准备公钥(模数和指数都可以),但验证失败..