使用 BC 密钥或默认密钥有什么区别?
两行代码:
KeyPairGenerator.getInstance("RSA")
KeyPairGenerator.getInstance("RSA", "BC")
效果很好。那么,使用 BC 与不使用 BC 有什么区别呢?
BC 与默认使用的 RSA 完全兼容吗? (使用Sun JDK 6)
Both lines of code:
KeyPairGenerator.getInstance("RSA")
KeyPairGenerator.getInstance("RSA", "BC")
works well. So, what's the differecente using BC or not?
Is BC completely compatible with the default RSA used? (using sun JDK 6)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 BouncyCastle FAQ 中,有一些与 RSA 实施细节相关的条目。
我个人还没有发现任何关于 Sun 和 BC 提供程序不兼容的文章,如果可以完全删除 BouncyCastle 依赖性,我建议使用 Java 的本机 RSA 实现。仅当有明确的好处时才应添加外部依赖项。
如果您在项目的其他地方使用 BC 库,我想使用哪个提供程序并不重要。
编辑
J2ME 不包括 RSA 实现。因此,如果您有时计划将应用程序移植到 J2ME,那么 BouncyCastle 库现在是正确的选择。
In BouncyCastle FAQ there are some entries related to RSA implementation details.
I personally haven't found anything written about Sun and BC providers being incompatible, and I suggest using Java's native RSA implementation if BouncyCastle dependency could be completely dropped by that. You should add external dependencies only if there is a well-defined benefit from that.
If you are using BC library somewhere else in your project, I guess it doesn't matter which provider to use.
EDIT
J2ME does not include RSA implementation. So if you are planning to port your app to J2ME sometimes, BouncyCastle library is the right way to go now.
来自 第一个构造函数的 Javadoc:
Security.getProviders()
的链接 Javadoc 依次说明以下内容:嗯,显然 BC 在您的情况下“巧合”是第一个首选提供者。如果它存在不确定性(即您想要分发应用程序并且无法控制最终用户的环境)并且您希望让它坚持使用 BC,那么您应该更喜欢使用第二个构造函数。
From the Javadoc of the first constructor:
The linked Javadoc of
Security.getProviders()
in turn states the following:Well, apparently BC is in your case "by coincidence" the first preferred provider. If there is uncertainity around it (i.e. you want to distribute the application and you have no control over enduser's environment) and you would like to let it stick to use BC, then you should prefer using the second constructor.
“BC”返回加密算法的 BouncyCastle 实现。
如果您不指定提供者,它将返回加密算法的“最优先”实现,即位置 1 的提供者是提供者数组中最优先的。
"BC" returns the BouncyCastle implementation of the crypto algorithm.
If you don't specify the provider it will return the "most prefferred" implementation of the crypto algorithm i.e. the providor at position 1 is the most preffered in the array of providers.