Last active
February 19, 2020 06:53
-
-
Save talhahasanzia/09f5a0c2c6b0050e3a8c43b78736bc61 to your computer and use it in GitHub Desktop.
Fix for EncryptionHelperLibrary for API 28 (Pie)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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