【问题标题】:Can you set the RSA public exponent to a value of your choice?您可以将 RSA 公共指数设置为您选择的值吗?
【发布时间】:2014-12-01 16:05:29
【问题描述】:

This 网站描述了一种使用库在 java 中实现 RSA 的方法。是否可以控制公共指数 e 的值? Java 将其设置为 65537。我知道这是一个合适的值,但我可以在仍然使用库的同时更改它吗?

他们是这样实现的:

KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(2048);
KeyPair kp = kpg.genKeyPair();
Key publicKey = kp.getPublic();
Key privateKey = kp.getPrivate();
KeyFactory fact = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pub = fact.getKeySpec(kp.getPublic(),
RSAPublicKeySpec.class);
RSAPrivateKeySpec priv = fact.getKeySpec(kp.getPrivate(),
RSAPrivateKeySpec.class);

saveToFile("public.key", pub.getModulus(),
pub.getPublicExponent());
saveToFile("private.key", priv.getModulus(),
priv.getPrivateExponent());

【问题讨论】:

    标签: java encryption cryptography rsa public-key-encryption


    【解决方案1】:

    是的,你可以,但你应该确定它是一个素数(以模的大小为界):

    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    // 17 is another often used value, beware to use proper RSA padding if you set it to 3
    RSAKeyGenParameterSpec kpgSpec = new RSAKeyGenParameterSpec(2048, BigInteger.valueOf(3));
    kpg.initialize(kpgSpec);
    KeyPair kp = kpg.genKeyPair();
    

    请注意,密钥生成后您无法更改它。另请注意,如果您的指数太大(或许多位设置为 1),则会影响公钥操作的速度。 65537 - 默认值 - 是一个很好的值,只有 2 位设置为 1(Fermat 的第四个数,或 F4)。

    【讨论】:

    • 还有微软旧的 32 位 CAPI 限制,如果您想与 .NET 软件互操作,这一点很重要。
    • @GregS 脑后有一盏小灯告诉我,我以前听说过这个限制。无论如何都不需要大指数,但有很好的附加信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多