Android密钥库已损坏 [英] Android keystore corrupted

查看:173
本文介绍了Android密钥库已损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间未更新Play商店中的应用程序后,我试图用我的密钥库对我的一个APK进行签名,结果发现密钥库和别名密码不再起作用.我可以使用以下要点重设密钥存储区密码: gist.github.com/zach-klippenstein/4631307 ,现在可以正常使用了.对于两个不同的应用程序,两个不同的密钥库都会发生这种情况.

运行 keytool -list -keystore mykeystore 导致:

 密钥库类型:JKS密钥库提供者:SUN您的密钥库包含1个条目myalias,2014年12月23日,PrivateKeyEntry,证书指纹(SHA1):85:8F:69 ...... 

我100%确定别名密码与密钥库密码相同,但是似乎不起作用.我曾尝试在Android Studio中使用 jarsigner -keystore mykeystore -storepass mykeystorepassword app-debug.apk myalias 对APK进行签名,但响应始终是: jarsigner:无法从密钥库中恢复密钥.

我尝试使用 keytool -importkeystore -srckeystore mykeystore -destkeystore newkeystore -srcalias myalias 将别名移动到新的密钥库文件,然后要求我输入新密钥库的新密码和密码.旧的密钥库(都可以),只有在输入别名密码后,我才会出现异常:

 输入目标密钥库密码:重新输入新的密码:输入源密钥库密码:输入< myalias>的密钥密码keytool错误:java.security.UnrecoverableKeyException:无法恢复密钥 

在谷歌搜索后,我发现对于某些人来说,密钥库在更新到另一个JDK版本或Android Studio版本后就停止工作了,所以我想知道对于我来说是否也是这种情况.密钥库创建于2014年,因此当时我可能使用的是JDK7(我现在是8岁).这也是可疑的两个密钥库神秘地停止工作.

可以通过某种方式解决此问题吗?

我尝试了Jan的解决方案,并得到了以下结果:

keytool -importkeystore -srckeystore mykeystore -destkeystore newkeystore -deststoretype pkcs12 给出了相同的异常: keytool错误:java.security.UnrecoverableKeyException:无法恢复密钥.>

运行此命令后: keytool -importkeystore -srckeystore newkeystore -srcstoretype pkcs12 -destkeystore finalkeystore -deststoretype jks 我收到此错误: keytool错误:java.io.IOException:DerInputStream.getLength():lengthTag = 109,太大.

第二

我还尝试使用JDK7在PC上签名apk,但不走运.

第三次

我尝试使用KeyStore Explorer,它可以很好地打开Keystore文件并显示一个条目(未过期).当我尝试打开私钥时,出现相同的异常.堆栈跟踪:

  java.security.UnrecoverableKeyException:无法恢复密钥在sun.security.provider.KeyProtector.recover(KeyProtector.java:328)在sun.security.provider.JavaKeyStore.engineGetKey(JavaKeyStore.java:146)在sun.security.provider.JavaKeyStore $ JKS.engineGetKey(JavaKeyStore.java:56)处在sun.security.provider.KeyStoreDelegator.engineGetKey(KeyStoreDelegator.java:96)在sun.security.provider.JavaKeyStore $ DualFormatJKS.engineGetKey(JavaKeyStore.java:70)在java.security.KeyStore.getKey(KeyStore.java:1023)在net.sf.keystore_explorer.gui.actions.KeyStoreExplorerAction.unlockEntry(KeyStoreExplorerAction.java:154)在net.sf.keystore_explorer.gui.actions.KeyStoreExplorerAction.getEntryPassword(KeyStoreExplorerAction.java:123)在net.sf.keystore_explorer.gui.actions.KeyPairPrivateKeyDetailsAction.doAction(KeyPairPrivateKeyDetailsAction.java:69)在net.sf.keystore_explorer.gui.actions.KeyStoreExplorerAction.actionPerformed(KeyStoreExplorerAction.java:93)在javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)在javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2348)在javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)在javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)在javax.swing.AbstractButton.doClick(AbstractButton.java:376)在javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)在javax.swing.plaf.basic.BasicMenuItemUI $ Handler.mouseReleased(BasicMenuItemUI.java:877)在java.awt.Component.processMouseEvent(Component.java:6535)在javax.swing.JComponent.processMouseEvent(JComponent.java:3324)在java.awt.Component.processEvent(Component.java:6300)在java.awt.Container.processEvent(Container.java:2236)在java.awt.Component.dispatchEventImpl(Component.java:4891)在java.awt.Container.dispatchEventImpl(Container.java:2294)在java.awt.Component.dispatchEvent(Component.java:4713)在java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)在java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)在java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)在java.awt.Container.dispatchEventImpl(Container.java:2280)在java.awt.Window.dispatchEventImpl(Window.java:2750)在java.awt.Component.dispatchEvent(Component.java:4713)在java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)在java.awt.EventQueue.access $ 500(EventQueue.java:97)在java.awt.EventQueue $ 3.run(EventQueue.java:709)在java.awt.EventQueue $ 3.run(EventQueue.java:703)在java.security.AccessController.doPrivileged(本机方法)在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)在java.awt.EventQueue $ 4.run(EventQueue.java:731)在java.awt.EventQueue $ 4.run(EventQueue.java:729)在java.security.AccessController.doPrivileged(本机方法)在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)在java.awt.EventQueue.dispatchEvent(EventQueue.java:728)在java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)在java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)在java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)在java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 

解决方案

尝试

  keytool -importkeystore -srckeystore old.keystore -destkeystore new.keystore -deststoretype pkcs12 

  keytool -importkeystore -srckeystore new.keystore -srcstoretype pkcs12 -destkeystore final.keystore -deststoretype jks 

根据此问题中的建议.

After a while of not updating my applications in the Play Store I tried to sign one of my APK with my keystore, only to find that the keystore and alias password doesn't work anymore. The keystore password I was able to reset using this gist: gist.github.com/zach-klippenstein/4631307 and works fine now. This happens for two different keystores for two different applications.

Running keytool -list -keystore mykeystore resulted in:

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

myalias, Dec 23, 2014, PrivateKeyEntry, 
Certificate fingerprint (SHA1): 85:8F:69......

I am 100% sure that the alias password is the same as the keystore password, but it doesn't seem to work. I've tried signing the APK in Android Studio and with jarsigner -keystore mykeystore -storepass mykeystorepassword app-debug.apk myalias but the response is always: jarsigner: unable to recover key from keystore.

I tried moving the alias to a new keystore file with keytool -importkeystore -srckeystore mykeystore -destkeystore newkeystore -srcalias myalias it then asks me to enter new password for the new keystore and the password for the old keystore (both work), only after entering the alias password I get an exception:

Enter destination keystore password:  
Re-enter new password: 
Enter source keystore password:  
Enter key password for <myalias>
keytool error: java.security.UnrecoverableKeyException: Cannot recover key

After some Googling I found that for some people the keystore stopped working after updating to another JDK version or Android Studio version, so I am wondering if that is the case for me also. The keystore was created in 2014 so I was probably on JDK7 at the time (I am now at 8). It is also suspicious two keystores mysteriously stop working..

Can this be fixed somehow?

EDIT:

I tried the solution from Jan and got the following results:

keytool -importkeystore -srckeystore mykeystore -destkeystore newkeystore -deststoretype pkcs12 gives me the same exception: keytool error: java.security.UnrecoverableKeyException: Cannot recover key.

After running this command: keytool -importkeystore -srckeystore newkeystore -srcstoretype pkcs12 -destkeystore finalkeystore -deststoretype jks I get this error: keytool error: java.io.IOException: DerInputStream.getLength(): lengthTag=109, too big.

SECOND EDIT:

I also tried signing the apk on a PC with JDK7, no luck.

THIRD EDIT:

I tried using the KeyStore Explorer and it opens the keystore file just fine and shows one entry (not expired). When I try to open the private key I get the same exception. Stacktrace:

java.security.UnrecoverableKeyException: Cannot recover key
at sun.security.provider.KeyProtector.recover(KeyProtector.java:328)
at sun.security.provider.JavaKeyStore.engineGetKey(JavaKeyStore.java:146)
at sun.security.provider.JavaKeyStore$JKS.engineGetKey(JavaKeyStore.java:56)
at sun.security.provider.KeyStoreDelegator.engineGetKey(KeyStoreDelegator.java:96)
at sun.security.provider.JavaKeyStore$DualFormatJKS.engineGetKey(JavaKeyStore.java:70)
at java.security.KeyStore.getKey(KeyStore.java:1023)
at net.sf.keystore_explorer.gui.actions.KeyStoreExplorerAction.unlockEntry(KeyStoreExplorerAction.java:154)
at net.sf.keystore_explorer.gui.actions.KeyStoreExplorerAction.getEntryPassword(KeyStoreExplorerAction.java:123)
at net.sf.keystore_explorer.gui.actions.KeyPairPrivateKeyDetailsAction.doAction(KeyPairPrivateKeyDetailsAction.java:69)
at net.sf.keystore_explorer.gui.actions.KeyStoreExplorerAction.actionPerformed(KeyStoreExplorerAction.java:93)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6535)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6300)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4891)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

解决方案

Try

keytool -importkeystore -srckeystore old.keystore -destkeystore new.keystore -deststoretype pkcs12

and

keytool -importkeystore -srckeystore new.keystore -srcstoretype pkcs12 -destkeystore final.keystore -deststoretype jks

as suggested in this question.

这篇关于Android密钥库已损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆