java - Cannot find any provider supporting AES/GCM/NoPadding -


we trying encryption supporting aes/gcm/nopadding in java 7 getting below exception.

cannot find provider supporting aes/gcm/nopadding

code sample generating cipher instance 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 not supported java 7 se (exception solaris).

public static void main(string[] args) throws exception {     (provider provider : security.getproviders()) {         (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 @ bouncy castle service provider in case.

small snippet using bouncycastle.

  1. download bcprov-jdk15on-154.jar http://www.bouncycastle.org/latest_releases.html
  2. register service provider in code

    security.addprovider(new bouncycastleprovider()); 
  3. then able use cipher (the paramter "bc" specifies use bounce castle service provider, can omitted if there no other provider same cipher)

    cipher c = cipher.getinstance("aes/gcm/nopadding", "bc"); 

java 8 support cipher out of box with

cipher c = cipher.getinstance("aes/gcm/nopadding"); 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -