Android Key Store using (between different apps)

45 views
Skip to first unread message

voks

unread,
Jun 19, 2015, 12:28:46 PM6/19/15
to android-...@googlegroups.com
Would appreciate any hint what I am missing in below code?
void addKeyToKeyStore() {
Calendar cal = Calendar.getInstance();
Date now = cal.getTime();
cal.add(Calendar.YEAR, 1);
Date end = cal.getTime();
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore");
kpg.initialize(new KeyPairGeneratorSpec.Builder(getApplicationContext())
.setAlias("MY_ALIAS")
.setStartDate(now)
.setEndDate(end)
.setSerialNumber(BigInteger.valueOf(1))
.setSubject(new X500Principal("CN=MY_ALIAS"))
.build());
}
void ListTheKeys() {
KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
ks.load(null);
final Enumeration<String> aliases = ks.aliases();
while(aliases.hasMoreElements()) {
Log.d(TAG, "Key Alias = "+aliases.nextElement());
}
String tempstr= "Entry for MY_ALIAS is " + (ks.isKeyEntry(key)? "exist" : "not exist");
Log.d(TAG, tempstr)
}
If same app calls addKeyToKeyStore() and then ListTheKeys() - the entry is exist. It also works if app restarted or phone rebooted. However if app1 calls addKeyToKeyStore() but app2 then calls ListTheKeys() - no entry that was added. Have tried set same sharedUserID in AndroidManifest(s) - no effect. I need to be able to access KeyStore from different apps. Thanks in advance!

voks

unread,
Jun 23, 2015, 8:07:43 PM6/23/15
to android-...@googlegroups.com
Never mind. I have figured out - a bit messed up with sharedUserID. If the sharedUserID declared properly .Everything works.
Issue can be closed.
Reply all
Reply to author
Forward
0 new messages