Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HmacSHA256 KeyGenerator not available #4382

Closed
youhere99 opened this issue Dec 1, 2020 · 11 comments
Closed

HmacSHA256 KeyGenerator not available #4382

youhere99 opened this issue Dec 1, 2020 · 11 comments
Assignees
Labels
status/invalid This doesn't seem right

Comments

@youhere99
Copy link

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtTokenUtils': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Unable to invoke class method io.jsonwebtoken.impl.crypto.MacProvider#generateKey. Ensure the necessary implementation is in the runtime classpath.
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:139)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:413)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1761)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:866)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
at com.alibaba.nacos.Nacos.main(Nacos.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: java.lang.IllegalStateException: Unable to invoke class method io.jsonwebtoken.impl.crypto.MacProvider#generateKey. Ensure the necessary implementation is in the runtime classpath.
at io.jsonwebtoken.lang.Classes.invokeStatic(Classes.java:202)
at io.jsonwebtoken.security.Keys.secretKeyFor(Keys.java:136)
at com.alibaba.nacos.console.utils.JwtTokenUtils.init(JwtTokenUtils.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
... 26 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.jsonwebtoken.lang.Classes.invokeStatic(Classes.java:198)
... 35 common frames omitted
Caused by: java.lang.IllegalStateException: The HmacSHA256 algorithm is not available. This should never happen on JDK 7 or later - please report this to the JJWT developers.
at io.jsonwebtoken.impl.crypto.MacProvider.generateKey(MacProvider.java:94)
at io.jsonwebtoken.impl.crypto.MacProvider.generateKey(MacProvider.java:63)
... 40 common frames omitted
Caused by: java.security.NoSuchAlgorithmException: HmacSHA256 KeyGenerator not available
at javax.crypto.KeyGenerator.(KeyGenerator.java:169)
at javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:223)
at io.jsonwebtoken.impl.crypto.MacProvider.generateKey(MacProvider.java:92)
... 41 common frames omitted
2020-12-01 23:17:41,451 WARN [WatchFileCenter] start close

2020-12-01 23:17:41,451 WARN [WatchFileCenter] start to shutdown this watcher which is watch : F:\nacos-server-1.4.0\nacos\conf

2020-12-01 23:17:41,451 WARN [WatchFileCenter] already closed

2020-12-01 23:17:41,451 WARN [NotifyCenter] Start destroying Publisher

2020-12-01 23:17:41,451 WARN [NotifyCenter] Destruction of the end

2020-12-01 23:17:41,451 ERROR Nacos failed to start, please see F:\nacos-server-1.4.0\nacos\logs\nacos.log for more details.

2020-12-01 23:17:41,464 INFO

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2020-12-01 23:17:41,466 ERROR Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtTokenUtils': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Unable to invoke class method io.jsonwebtoken.impl.crypto.MacProvider#generateKey. Ensure the necessary implementation is in the runtime classpath.
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:139)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:413)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1761)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:866)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
at com.alibaba.nacos.Nacos.main(Nacos.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: java.lang.IllegalStateException: Unable to invoke class method io.jsonwebtoken.impl.crypto.MacProvider#generateKey. Ensure the necessary implementation is in the runtime classpath.
at io.jsonwebtoken.lang.Classes.invokeStatic(Classes.java:202)
at io.jsonwebtoken.security.Keys.secretKeyFor(Keys.java:136)
at com.alibaba.nacos.console.utils.JwtTokenUtils.init(JwtTokenUtils.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
... 26 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.jsonwebtoken.lang.Classes.invokeStatic(Classes.java:198)
... 35 common frames omitted
Caused by: java.lang.IllegalStateException: The HmacSHA256 algorithm is not available. This should never happen on JDK 7 or later - please report this to the JJWT developers.
at io.jsonwebtoken.impl.crypto.MacProvider.generateKey(MacProvider.java:94)
at io.jsonwebtoken.impl.crypto.MacProvider.generateKey(MacProvider.java:63)
... 40 common frames omitted
Caused by: java.security.NoSuchAlgorithmException: HmacSHA256 KeyGenerator not available
at javax.crypto.KeyGenerator.(KeyGenerator.java:169)
at javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:223)
at io.jsonwebtoken.impl.crypto.MacProvider.generateKey(MacProvider.java:92)
... 41 common frames omitted

@youhere99
Copy link
Author

nacos team look look

@paderlol paderlol added the kind/user experience not necessarily an error but can be improved for user experience label Dec 1, 2020
@paderlol
Copy link
Collaborator

paderlol commented Dec 1, 2020

This problem has nothing to do with Nacos. It is a problem of your jdk itself. You need to check your JDK or upgrade the JDK version. There are many similar problems on the Internet, you can search for it.

@youhere99
Copy link
Author

This problem has nothing to do with Nacos. It is a problem of your jdk itself. You need to check your JDK or upgrade the JDK version. There are many similar problems on the Internet, you can search for it.

jdk1.8.0_271

@KomachiSion KomachiSion added dependencies Pull requests that update a dependency file and removed kind/user experience not necessarily an error but can be improved for user experience labels Dec 1, 2020
@KomachiSion
Copy link
Collaborator

From the error information, JJWT want use HmacSHA256 of JDK, but some error happened. And it can't be report in my env.

I think you can report this problem to JJWT. Or re-install jdk, and check java home and check nacos use right jdk to start.

@horizonzy
Copy link
Collaborator

    public static void main(String[] args) {
        try {
            KeyGenerator hmacSHA256 = KeyGenerator.getInstance("HmacSHA256");
            System.out.println("111");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }

run this demo, can you run it normally?

@youhere99
Copy link
Author

在linux 上运行成功,在windows升级jdk也是报同样的错,

@horizonzy
Copy link
Collaborator

在linux 上运行成功,在windows升级jdk也是报同样的错,

java -version看一下你的jdk的版本。贴一下

@horizonzy
Copy link
Collaborator

image

我的windows机器jdk也是1.8.0_271版本,能够支持HmacSHA256算法。能提供一下你的运行时的环境信息吗。

@paderlol
Copy link
Collaborator

paderlol commented Dec 4, 2020

@KomachiSion
Copy link
Collaborator

It‘s not nacos' problem I think, and author no response more than 7 days, so we think the problem has been fixed. Close issue.

@KomachiSion KomachiSion added status/invalid This doesn't seem right and removed dependencies Pull requests that update a dependency file status/need feedback labels Dec 11, 2020
@wlyu
Copy link

wlyu commented Feb 20, 2021

@youhere99 window==set JAVA="D:\soft\Java\jdk1.8.0_201\bin\java.exe"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

5 participants