com.sun.net.ssl.internal.ssl.Provider() 的遗留 Java 代码使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13160829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 11:42:31  来源:igfitidea点击:

Legacy Java code use of com.sun.net.ssl.internal.ssl.Provider()

javasslproviderlegacy

提问by Dan

I am working with some code from back in 2003. There is a reference to the following class:

我正在使用 2003 年的一些代码。有对以下类的引用:

new com.sun.net.ssl.internal.ssl.Provider()

It is causing an error:

它导致错误:

Access restriction: The type Provider is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/jre/lib/jsse.jar

Access restriction: The type Provider is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/jre/lib/jsse.jar

Does anyone have any suggestions for a suitable alternative to using this class?

有没有人对使用此类的合适替代方法有任何建议?

回答by Bruno

Most of the time, you don't actually need to create or get hold of a provider instance yourself. As the Oracle Providers documentationsays:

大多数情况下,您实际上并不需要自己创建或获取提供程序实例。正如Oracle Providers 文档所说:

General purpose applications SHOULD NOT request cryptographic services from specific providers. That is:

getInstance("...", "SunJCE");  // not recommended
    vs.
getInstance("...");            // recommended

通用应用程序不应向特定提供者请求加密服务。那是:

getInstance("...", "SunJCE");  // not recommended
    vs.
getInstance("...");            // recommended

In addition, wherever there's an overloaded parameter for the provider, it tends to take either a string or an instance, but the string (name) would probably be more common. (Passing an instance can be useful sometimes, e.g. for some PKCS#11 configurations, but it's unusual.)

此外,无论在何处存在用于提供程序的重载参数,它都倾向于采用字符串或实例,但字符串(名称)可能更常见。(传递实例有时很有用,例如对于某些 PKCS#11 配置,但这是不寻常的。)

The JCA documentation about Providersshould be useful.

关于提供者JCA 文档应该很有用。

If you really want to get hold of a specific instance, you can use Security.getProvider(name). You'll find the appropriate names in the providers documentation.

如果你真的想掌握一个特定的实例,你可以使用Security.getProvider(name). 您将在提供者文档中找到适当的名称。

回答by user207421

Throw that line of code away. Also throw away any reference to the com.sun.net.sslpackage and its sub-packages: fix the imports so they refer to the classes in javax.net.ssl.

扔掉那行代码。同时丢弃对com.sun.net.ssl包及其子包的任何引用:修复导入,以便它们引用中的类javax.net.ssl.

This is pre-JDK 1.4 code, from the days when JSSE was a separate download.

这是 JDK 1.4 之前的代码,从 JSSE 是单独下载的时代开始。

回答by Martin Serrano

You can turn this into a warning or non-event in Eclipse preferences Java->Compiler->Errors/Warnings->Deprecated and restricted API. Note, as others have said, this not the best practice and should be avoided when you have alternatives.

您可以在 Eclipse 首选项中将其转换为警告或非事件Java->Compiler->Errors/Warnings->Deprecated and restricted API。请注意,正如其他人所说,这不是最佳实践,当您有其他选择时应该避免。