Java。无法从导入java.security.Signature导入SHA256withRSA签名

时间:2018-08-07 20:52:19

标签: java encryption java-security rsa-sha256

我正在尝试初始化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
...

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

0 个答案:

没有答案