14
私は(自分で作られた)ウェブサービスから受けるベース64文字列にエンコードされたRSAのPrivateKey PKCS#8を保存する方法。 私のAndroidアプリはこのキーを携帯電話のどこかに安全に保存する必要があります。Androidのキーストア - RSAのPrivateKey
のAndroidの4.3バージョンから、それは新しいキーストアのAPIを使用して可能省キーです。 私は鍵を格納するために必要な仕様に鍵ペアを生成する方法を示しarticle with code axampleを見つけました。その後、キーを回復する。
// generate a key pair
Context ctx = getContext();
Calendar notBefore = Calendar.getInstance()
Calendar notAfter = Calendar.getInstance();
notAfter.add(1, Calendar.YEAR);
KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(ctx)
.setAlias("key1")
.setSubject(
new X500Principal(String.format("CN=%s, OU=%s", alais,
ctx.getPackageName())))
.setSerialNumber(BigInteger.ONE).setStartDate(notBefore.getTime())
.setEndDate(notAfter.getTime()).build();
KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore");
kpGenerator.initialize(spec);
KeyPair kp = kpGenerator.generateKeyPair();
// in another part of the app, access the keys
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
KeyStore.PrivateKeyEntry keyEntry = (KeyStore.PrivateKeyEntry)keyStore.getEntry("key1", null);
RSAPublicKey pubKey = (RSAPublicKey)keyEntry.getCertificate().getPublicKey();
RSAPrivateKey privKey = (RSAPrivateKey) keyEntry.getPrivateKey();
しかし、私はそれに既存のキーを保存する方法を理解できません。誰か助けてくれますか? ありがとうございます。
http://nelenkov.blogspot.com/2012/05/storing-application-secrets-in-androids.html –