Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA无法从导入java.security.signature导入带有RSA签名的SHA256withRSA_Java_Encryption_Java Security_Rsa Sha256 - Fatal编程技术网

JAVA无法从导入java.security.signature导入带有RSA签名的SHA256withRSA

JAVA无法从导入java.security.signature导入带有RSA签名的SHA256withRSA,java,encryption,java-security,rsa-sha256,Java,Encryption,Java Security,Rsa Sha256,我正在尝试使用RSA签名对象初始化SHA256: Signature signer = Signature.getInstance("SHA256withRSA"); 但编译器会生成NoSuchAlgorithmException,但当我运行此代码时: import java.security.Signature; public static void main(String[] args) throws IOException{ TreeSet<String> algo

我正在尝试使用RSA签名对象初始化SHA256:

Signature signer = Signature.getInstance("SHA256withRSA");
但编译器会生成
NoSuchAlgorithmException
,但当我运行此代码时:

import java.security.Signature;

public static void main(String[] args) throws IOException{
    TreeSet<String> algorithms = new TreeSet<>();
    for (Provider provider : Security.getProviders())
        for (Provider.Service service : provider.getServices())
            if (service.getType().equals("Signature"))
                algorithms.add(service.getAlgorithm());
    for (String algorithm : algorithms)
        System.out.println(algorithm);
}

我做错了什么,或者我应该在项目中包含哪些库?

您可以包含不起作用的代码吗?谢谢您的回复!问题更新了。我尝试了这个,代码运行正常。您使用的是哪个版本的Java?注意:OpenJDK没有与OracleJDK相同的加密选项。该异常在运行时来自JVM,而不是编译器。但是如果一个算法在服务列表中,你应该能够实例化它。你发布的代码有错误的引号,根本不应该编译;确保你的真实代码没有,如果它已经暴露在Windows中(它喜欢像那样弄乱引号),也要检查它没有任何不可见的字符,比如BOM或bidi标记之类的。
...
SHA256withECDSAinP1363Format
SHA256withRSA
SHA384withECDSA
...