Skip to content

Unable to initialize due to invalid secret key

Yeh-Yung Chang edited this page Jun 15, 2015 · 1 revision

Description

If you are using Oracle JDK or JRE and got one of the following exception messages.

java.lang.IllegalArgumentException: Unable to initialize due to invalid secret key
	at org.springframework.security.crypto.encrypt.CipherUtils.initCipher(CipherUtils.java:120)
	at org.springframework.security.crypto.encrypt.AesBytesEncryptor.encrypt(AesBytesEncryptor.java:67)
	at org.springframework.security.crypto.encrypt.HexEncodingTextEncryptor.encrypt(HexEncodingTextEncryptor.java:36)
	at tw.edu.ncu.cc.oauth.server.concepts.security.SecretServiceImpl.encrypt(SecretServiceImpl.groovy:55)
	at tw.edu.ncu.cc.oauth.server.concepts.authorizationCode.AuthorizationCodeServiceImpl.create(AuthorizationCodeServiceImpl.groovy:30)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
	at tw.edu.ncu.cc.oauth.server.service.domain.AuthorizationCodeServiceImplTest.it can create authorization code(AuthorizationCodeServiceImplTest.groovy:27)
Caused by: java.security.InvalidKeyException: No installed provider supports this key: javax.crypto.spec.SecretKeySpec
	at javax.crypto.Cipher.chooseProvider(Cipher.java:893)
	at javax.crypto.Cipher.init(Cipher.java:1396)
	at javax.crypto.Cipher.init(Cipher.java:1327)
	at org.springframework.security.crypto.encrypt.CipherUtils.initCipher(CipherUtils.java:113)
	... 13 more
java.lang.IllegalArgumentException: Unable to initialize due to invalid secret key
	at org.springframework.security.crypto.encrypt.CipherUtils.initCipher(CipherUtils.java:120)
	at org.springframework.security.crypto.encrypt.AesBytesEncryptor.encrypt(AesBytesEncryptor.java:67)
	at org.springframework.security.crypto.encrypt.HexEncodingTextEncryptor.encrypt(HexEncodingTextEncryptor.java:36)
	at tw.edu.ncu.cc.oauth.server.concepts.security.SecretServiceImpl.encrypt(SecretServiceImpl.groovy:55)
	at tw.edu.ncu.cc.oauth.server.concepts.security.SecretServiceImplTest.it can encrypt/decrypt text(SecretServiceImplTest.groovy:34)
Caused by: java.security.InvalidKeyException: Illegal key size
	at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1039)
	at javax.crypto.Cipher.implInit(Cipher.java:805)
	at javax.crypto.Cipher.chooseProvider(Cipher.java:864)
	at javax.crypto.Cipher.init(Cipher.java:1396)
	at javax.crypto.Cipher.init(Cipher.java:1327)
	at org.springframework.security.crypto.encrypt.CipherUtils.initCipher(CipherUtils.java:113)
	... 4 more

Possible solution

  • Download Java Cryptography Extension of your jdk or jre version.
  • Copy local_policy.jar and US_export_policy.jar to you {java_location}/lib/security.
Clone this wiki locally