Java RSA如何生成不同的公钥?
我在 java 中为 RSA 生成公钥时遇到问题。我使用 KeyPairGenerator 获得公钥、私钥、p、q 和模数。没关系。但是每次公钥都是65537。是否有可能每次生成不同的公钥?
代码:
KeyPair keys;
KeyPairGenerator generator;
try {
generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(1024);
keys = generator.genKeyPair();
} catch (NoSuchAlgorithmException ex) {}
I have a problem with generating public key for RSA in java. I use KeyPairGenerator and I get public, private key, p, q and modulus. It is fine. But everytime public key is a 65537. Is there any posibility to generate different public key each time?
Code:
KeyPair keys;
KeyPairGenerator generator;
try {
generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(1024);
keys = generator.genKeyPair();
} catch (NoSuchAlgorithmException ex) {}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
值 65537 是常用的 RSA 密钥指数。该值是固定的并且没有安全隐患,这并不奇怪。
有许多已知的弱指数已知 - 但这个值不属于它。
The value 65537 is the commonly used exponent of RSA keys. It is nothing unusual that this value is fixed and has no security implications.
There are a number of known weak exponents known - but this value does not belong to it.
公钥不能简单地是 65537,因为在 RSA 中,公钥是一对 (n,e),其中 n 是模数,e 是指数。通常,指数等于 65537,变化的是模数。
因此,为了确保每次生成不同的密钥,请检查模数是否发生变化。
The public key can't be simply 65537, since in RSA a public key is a pair (n,e) where n is the modulus and e is the exponent. Typically, the exponent is equal to 65537, and it is the modulus that changes.
So, in order to make sure you are generating different keys every time, check that the modulus is changing.