question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

key spec not recognized

See original GitHub issue

Hello.

I am trying to use webpush-java with a web page and I created a Java test application (Jar file) to try it. But I have a problem:

When I run the test in the Windows prompt I get success and a push notification in my workstation, but when I run the test in the CMS (Opencms - Tomcat) I get the error:

09 ago 2018 11:44:17,794 ERROR [s.scheduler.CmsScheduleManager: 576] Error executing scheduled job "teste para notificacao".
**java.security.spec.InvalidKeySpecException: key spec not recognized**
	at org.bouncycastle.jcajce.provider.asymmetric.util.BaseKeyFactorySpi.engineGeneratePublic(Unknown Source)
	at org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi.engineGeneratePublic(Unknown Source)
	at java.security.KeyFactory.generatePublic(Unknown Source)
	at nl.martijndwars.webpush.Utils.loadPublicKey(Utils.java:70)
	at nl.martijndwars.webpush.Notification.<init>(Notification.java:51)
	at PushServiceTest.testPushChromeVapid(PushServiceTest.java:69)
	at disparaTeste.launch(disparaTeste.java:22)
	at org.opencms.scheduler.CmsScheduleManager.executeJob(CmsScheduleManager.java:568)
	at org.opencms.scheduler.CmsScheduleManager$1.run(CmsScheduleManager.java:170)

I think the problem is in the command:

pushService.setPublicKey(Utils.loadPublicKey("BOH8nTQA5iZhl23+NCzGG9prvOZ5BE0MJXBW+GUkQIvRVTVB32JxmX0V1j6z0r7rnT7+bgi6f2g5fMPpAh5brqM="));

Have you some suggestion to solve the problem?

Thanks a lot.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tercioramalhocommented, Aug 13, 2018

You were correct. The problem was solved. Thanks a lot.

0reactions
sudhanshu1693commented, Jan 14, 2019

I Think you are providing a null value instead an arrayBuffer. Obter o Outlook para Androidhttps://aka.ms/ghei36 ________________________________ From: sudhanshu1693 notifications@github.com Sent: Friday, January 11, 2019 9:53:45 AM To: web-push-libs/webpush-java Cc: tercioramalho; Author Subject: Re: [web-push-libs/webpush-java] key spec not recognized (#65) Hi I want to implement push notification in Liferay. I have created push notification from Servlet where I am able to send push notification on Mozilla Firefox but in Google Chrome am getting Error .TypeError: Failed to execute ‘subscribe’ on ‘PushManager’: The provided value is not of type ‘(ArrayBuffer or ArrayBufferView)’ below is the code where i am getting error navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) { console.log(serviceWorkerRegistration.pushManager.getSubscription()); serviceWorkerRegistration.pushManager.getSubscription().then(function (subscription) { if (!subscription) { console.log(subscription); subscribe(); return; } sendSubscriptionToServer(subscription); }) .catch(function(err) { console.warn('Error during getSubscription()', err); }); }); This error is only in google chrome. In Liferay, I have used the same code but while submitting request I am getting below Error. java.security.spec.InvalidKeySpecException: key spec not recognized at org.bouncycastle.jcajce.provider.asymmetric.util.BaseKeyFactorySpi.engineGeneratePublic(Unknown Source) at org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi.engineGeneratePublic(Unknown Source) at java.security.KeyFactory.generatePublic(KeyFactory.java:328) at nl.martijndwars.webpush.Utils.loadPublicKey(Utils.java:55) at nl.martijndwars.webpush.Notification.(Notification.java:62) at nl.martijndwars.webpush.Notification.(Notification.java:66) at com.push.notification.portlet.PushNotificationPortlet.sendNotification(PushNotificationPortlet.java:35) at com.push.notification.portlet.PushNotificationPortlet.doView(PushNotificationPortlet.java:60) at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:305) at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:497) at javax.portlet.GenericPortlet.render(GenericPortlet.java:291) at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.render(MVCPortlet.java:317) at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:127) at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:58) at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:124) at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71) at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:108) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153) at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:62) at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:118) at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48) I have followed as per your guideline and also added security.provider.11=org.bouncycastle.jce.provider.BouncyCastleProvider in java.security and i have addded bcprov-jdk15on-1.60.jar in jre/lib/ext. can you please help me on this I have tried all possible combinations. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub<#65 (comment)>, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AoDqlxxvtW_JvBc9sgbX6e70Zb8c1AJSks5vCIlZgaJpZM4V2LXq.

No, I am not passing null

below is the sample of input and output what i am getting.

async function urlB64ToUint8Array(base64String){
		  const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
		  const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/');
		  const rawData = atob(base64);
		  const outputArray = new Uint8Array(rawData.length);
		  for (var i = 0; i < rawData.length; ++i) {
		    outputArray[i] = rawData.charCodeAt(i);
		  }
		  console.log("output array is : "+outputArray);
		  return outputArray;
	}

Input BN7JDTjiYI5Gcmi9OuNNggbRZG5ltDQfW0XiAUgHKaOiDnrrYC5nr6MgzsApJPf-C_SrIRQfTKWtFHzPIqbvYsI=

Output

Uint8Array(65) [4, 222, 201, 13, 56, 226, 96, 142, 70, 114, 104, 189, 58, 227, 77, 130, 6, 209, 100, 110, 101, 180, 52, 31, 91, 69, 226, 1, 72, 7, 41, 163, 162, 14, 122, 235, 96, 46, 103, 175, 163, 32, 206, 192, 41, 36, 247, 254, 11, 244, 171, 33, 20, 31, 76, 165, 173, 20, 124, 207, 34, 166, 239, 98, 194]

Read more comments on GitHub >

github_iconTop Results From Across the Web

InvalidKeyException: Key Spec Not Recognised - java
The weird thing is that my encryptFile method works perfectly, but decryptFile is throwing the error. I'm not entirely sure why.
Read more >
java.security.spec.InvalidKeySpecException: key spec not ...
RE: java.security.spec.InvalidKeySpecException: key spec not recognized ... I found the solution this error comes because of the bouncycastle jar. I have used web ......
Read more >
java.security.spec.InvalidKeySpecException: key spec not ...
I'm asking, because DSA keys have been disabled for some time now on most Linux distributions for security reasons. Apparently, those have now...
Read more >
InvalidKeySpecException during client authentication with ...
PemException: java.security.spec.InvalidKeySpecException: encoded key spec not recognized: algorithm identifier 1.2.840.10045.2.1 in key not recognised.
Read more >
JGit exception java.security.spec.InvalidKeySpecException ...
EdDSAPublicKeySpec: java.security.spec.InvalidKeySpecException: key spec not recognised: class net.i2p.crypto.eddsa.spec.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found