简体   繁体   English

如何以十六进制格式从密钥库中提取私钥

[英]How to extract private key from Keystore in hexadecimal format

KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
KeyStore.Entry entry = keyStore.getEntry("ECKey", null);
PrivateKey privateKey = ((KeyStore.PrivateKeyEntry) entry).getPrivateKey();
PublicKey publicKey = keyStore.getCertificate("ECKey").getPublicKey();

Log.d(TAG, "Private:" + privateKey.getEncoded());

This code returns encoded private key "null". 此代码返回已编码的私钥“ null”。 What is the way to extract the key. 提取密钥的方法是什么。

There is no way. 不可能。 This is the purpose of AndroidKeyStore. 这就是AndroidKeyStore的目的。 Keys created in it cannot be extracted, which means the key material can't be leaked even to an attacker who compromises the Android OS. 无法提取在其中创建的密钥,这意味着即使泄露给破坏Android操作系统的攻击者也不会泄漏密钥材料。

If you want to have a private key you can export, you should create the key outside of AndroidKeyStore, save a copy of the private key, then import it. 如果要拥有可以导出的私钥,则应在AndroidKeyStore外部创建密钥,保存私钥的副本,然后导入。 Keystore will keep secure the imported copy. 密钥库将确保导入副本的安全。 Be sure not to leak the copy you hold (this is actually pretty hard). 确保不要泄漏您持有的副本(这实际上很难)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM