Otrzymuję od usługi sieciowej (wykonanej przeze mnie) RSA PrivateKey PKCS # 8 zakodowanej w 64-bitowym łańcuchu bazowym. Moja aplikacja na Androida musi bezpiecznie zapisać ten klucz w telefonie.Android KeyStore - jak zapisać klucz prywatny RSA
Z wersji 4.3 systemu Android możliwe jest zapisywanie kluczy przy użyciu nowego interfejsu API KeyStore. Znalazłem article with code axample, który pokazuje, jak wygenerować KeyPair ze Specyfikacją potrzebną do przechowywania kluczy. A potem odzyskać klucze.
// 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();
Ale nie rozumiem, jak mogę zapisać istniejący klucz do niego. Czy ktoś może mi pomóc? Z góry z góry
http://nelenkov.blogspot.com/2012/05/storing-application-secrets-in-androids.html –