1
RSAキーペアを格納するためにAndroidキーストアAPIを使用しています。Android KeyStoreでRSAキーが保存されない
アンドロイドをデバッグモードで実行すると、キーペアと証明書のバイトがキーストアに格納されていることがわかりますが、デバッガをリロードしてキーを取得しようとすると、キーストアは空に見えます。
エイリアスでキーを取得できるようにします。以下の私のコードは、鍵ペアがどのように作成され格納されるかを示しています。
あなたは、ファイルシステム内のキーストアを作成することができ、あなたのコードでpublic RSA(char[] password) throws Exception {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null);
Enumeration<String> aliases = ks.aliases();
if(!aliases.hasMoreElements())
{
mCurrentCertificate = generateCert();
//Store the new keypair
FileInputStream fs = null;
ks.load(fs, password);
KeyStore.ProtectionParameter protParam =
new KeyStore.PasswordProtection(password);
java.security.cert.Certificate[] myCert =
new java.security.cert.Certificate[] { (java.security.cert.Certificate) mCurrentCertificate};
KeyStore.PrivateKeyEntry pkEntry =
new KeyStore.PrivateKeyEntry(mCurrentRSAKeyPair.getPrivate(),
myCert);
ks.setEntry("MyKey2", pkEntry, protParam);
for(int i = 0; i < ks.size(); i++)
{
//MyKey is the previous key stored, MyKey2 is the next one
System.out.println(ks.getCertificate("MyKey"));
}
}
}