java程序生成的加密密钥不被微软加密API接受
我们已经通过java程序生成了RSA公钥,以便在传输数据之前用C++加密数据,但是当我们使用此密钥使用Microsoft加密API加密数据时,它不接受此密钥。
有人对此有什么想法吗?
We have generated RSA public key by our java program to encrypt the data in C++ before transmitting it but when we use this key to encrypt the data using Microsoft encryption API, it doesn't accepts this key.
Do anyone has any ideas on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我的经验,Java 和 MS 之间的 RSA 密钥序列化是不同的。
但是,我所做的是使用 Bouncy Castle API 来完成此操作,因为他们的库有 Java 和 .NET 版本。
有关更多选项,您可以看看这个问题:
RSA:如何生成私有密钥在java中键入并在C#中使用它?
In my experience the serialization of an RSA key is different between Java and MS.
But, what I did was to use the Bouncy Castle API to do this, as they have a Java and .NET version of their library.
For more options you can look at this question:
RSA: How to generate private key in java and use it in C#?
Microsoft 代码对其可以使用的 RSA 密钥有一些固有的限制:它要求公钥长度(模位长度)是 16 的倍数,并且公共指数必须适合 32 位无符号整数。
然而,大多数 RSA 密钥都符合这些限制,通常的怀疑是编码/解码问题。 Java 倾向于在任何地方使用大端字节序,因为:
另一方面,微软的 CryptoAPI 想要小端。您可能以错误的顺序使用了公共模数。
Microsoft code has some intrinsic limitations on what RSA keys it can use: it requires the public key length (the modulus bit length) to be a multiple of 16, and the public exponent must fit in a 32-bit unsigned integer.
However, most RSA keys fit in those constraints and the usual suspects are encoding/decoding issues. Java tends to use big-endian everywhere, because:
On the other hand, Microsoft's CryptoAPI wants little-endian. You may have used your public modulus in the wrong order.