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

algorithm identifier 1.2.840.10045.2.1 in key not recognised #24

Open
mahermeg17 opened this issue Jul 14, 2016 · 0 comments
Open

algorithm identifier 1.2.840.10045.2.1 in key not recognised #24

mahermeg17 opened this issue Jul 14, 2016 · 0 comments

Comments

@mahermeg17
Copy link

mahermeg17 commented Jul 14, 2016

Hi,
need to convert pkcs8 to pkcs12 so I used this code to load privatekey from pkcs8 file :

public static PrivateKey loadPrivateKey(String keyFile) { try { File f = new File(keyFile); FileInputStream fis = null; fis = new FileInputStream(f); DataInputStream dis = new DataInputStream(fis); byte[] keyBytes = new byte[(int) f.length()]; dis.readFully(keyBytes); dis.close(); PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes); KeyFactory kf = KeyFactory.getInstance("RSA"); PrivateKey pk = kf.generatePrivate(spec); return pk; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (InvalidKeySpecException e) { e.printStackTrace(); } return null; }

but I have an exception org.spongycastle.jcajce.provider.asymmetric.util.ExtendedInvalidKeySpecException

org.spongycastle.jcajce.provider.asymmetric.util.ExtendedInvalidKeySpecException: unable to process key spec: java.io.IOException: algorithm identifier 1.2.840.10045.2.1 in key not recognised at org.spongycastle.jcajce.provider.asymmetric.rsa.KeyFactorySpi.engineGeneratePrivate(KeyFactorySpi.java:105) at java.security.KeyFactory.generatePrivate(KeyFactory.java:186) at org.XXXXXX.loadPrivateKey(CertProvider.java:45) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Caused by: java.io.IOException: algorithm identifier 1.2.840.10045.2.1 in key not recognised at org.spongycastle.jcajce.provider.asymmetric.rsa.KeyFactorySpi.generatePrivate(KeyFactorySpi.java:153) at org.spongycastle.jcajce.provider.asymmetric.rsa.KeyFactorySpi.engineGeneratePrivate(KeyFactorySpi.java:91) ... 17 more

any indication to solve this? or may SC on android can handle *.pkcs8, so I don't need to convert to pkcs12 (at least for this momment I just need *.pkcs8 files).

THX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant