Skip to content

Instantly share code, notes, and snippets.

@talhahasanzia
Last active February 19, 2020 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talhahasanzia/09f5a0c2c6b0050e3a8c43b78736bc61 to your computer and use it in GitHub Desktop.
Save talhahasanzia/09f5a0c2c6b0050e3a8c43b78736bc61 to your computer and use it in GitHub Desktop.
Fix for EncryptionHelperLibrary for API 28 (Pie)
private PrivateKey getPrivateKey(String alias) throws UnrecoverableEntryException, NoSuchAlgorithmException, KeyStoreException {
//private key
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
return (PrivateKey) keyStore.getKey(alias, null);
} else {
return ((KeyStore.PrivateKeyEntry) keyStore.getEntry(alias, null)).getPrivateKey();
}
}
private PublicKey getPublicKey(String alias) throws KeyStoreException, UnrecoverableEntryException, NoSuchAlgorithmException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
return keyStore.getCertificate(alias).getPublicKey();
} else {
return ((KeyStore.PrivateKeyEntry) keyStore.getEntry(alias, null)).getCertificate().getPublicKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment