Cannot find any provider supporting AES/GCM/NoPadding
12,331
This cipher is not supported by Java 7 SE (exception for 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.
Small snippet for using Bouncycastle.
- download
bcprov-jdk15on-154.jar
from http://www.bouncycastle.org/latest_releases.html -
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)Cipher c = Cipher.getInstance("AES/GCM/NOPADDING", "BC");
Java 8 support the cipher out of the box with
Cipher c = Cipher.getInstance("AES/GCM/NOPADDING");
![dReAmEr](https://i.stack.imgur.com/RPXzs.jpg?s=256&g=1)
Comments
-
dReAmEr about 2 years
We are trying to do encryption supporting AES/GCM/NoPadding in java 7 getting below exception.
Cannot find any provider supporting 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));
-
dReAmEr about 8 yearsThanks a lot for this information,do you have any sample code how to use AES/GCM/Padding with Bounty Castle,really appreciate.
-
SubOptimal about 8 years@RE350 I added the necessary lines into my answer. The main thing you need to do is to register the new service provider.