我正在尝试初始化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
...
我做错了什么或应该在项目中包括哪些库?