[英]Cannot find any provider supporting AES/GCM/NoPadding
We are trying to do encryption supporting AES/GCM/NoPadding in java 7 getting below exception. 我们正在尝试进行加密,支持java 7中的 AES / GCM / NoPadding获得以下异常。
Cannot find any provider supporting AES/GCM/NoPadding 找不到任何支持AES / GCM / NoPadding的提供商
Code sample for generating cipher instance is below. 用于生成密码实例的代码示例如下。
SecretKeySpec eks = new SecretKeySpec(k, "AES");
Cipher c = Cipher.getInstance("AES/GCM/NoPadding");
c.init(Cipher.ENCRYPT_MODE, eks, new GCMParameterSpec(128, iv));
This cipher is not supported by Java 7 SE ( exception for Solaris ). Java 7 SE不支持此密码( Solaris的例外 )。
public static void main(String[] args) throws Exception {
for (Provider provider : Security.getProviders()) {
for (Map.Entry<Object, Object> entry : provider.entrySet()) {
if (((String) entry.getValue()).contains("GCM")) {
System.out.printf("key: [%s] value: [%s]%n",
entry.getKey(),
entry.getValue());
}
}
}
}
You might have a look at Bouncy Castle as service provider in that case. 在这种情况下,您可以将Bouncy Castle视为服务提供商。
Small snippet for using Bouncycastle. 使用Bouncycastle的小片段。
bcprov-jdk15on-154.jar
from http://www.bouncycastle.org/latest_releases.html 从http://www.bouncycastle.org/latest_releases.html下载bcprov-jdk15on-154.jar
register the service provider in your code 在您的代码中注册服务提供商
Security.addProvider(new BouncyCastleProvider());
then you are able to use the cipher as (the paramter "BC"
specifies to use Bounce Castle as service provider, can be omitted if there is no other provider for the same cipher) 然后你就可以使用密码了(参数"BC"
指定使用Bounce Castle作为服务提供者,如果同一个密码没有其他提供者,则可以省略)
Cipher c = Cipher.getInstance("AES/GCM/NOPADDING", "BC");
Java 8 support the cipher out of the box with Java 8支持开箱即用的密码
Cipher c = Cipher.getInstance("AES/GCM/NOPADDING");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.