0

我正在尝试初始化 SHA256withRSA 签名对象:

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);
}

它创建输出:

...
SHA256withECDSAinP1363Format
SHA256withRSA
SHA384withECDSA
...

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

4

0 回答 0