code: private KeyStore.PrivateKeyEntry getKeyEntryCompat(KeyStore keyStore) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException {
          if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
              return (KeyStore.PrivateKeyEntry) keyStore.getEntry(KEY_ALIAS, null);
          }
  
          //Following code is for API 28+
          PrivateKey privateKey = (PrivateKey) keyStore.getKey(KEY_ALIAS, null);
  
          if (privateKey == null) {
              return (KeyStore.PrivateKeyEntry) keyStore.getEntry(KEY_ALIAS, null);
          }
  
          Certificate certificate = keyStore.getCertificate(KEY_ALIAS);
          return new KeyStore.PrivateKeyEntry(privateKey, new Certificate[]{certificate});
      }
docs: Helper method compatible with older Android versions to load the Private Key Entry from
  the KeyStore using the {@link #KEY_ALIAS}.
  
  @param keyStore the KeyStore instance. Must be initialized (loaded).
  @return the key entry stored in the KeyStore.
  @throws KeyStoreException           if the keystore was not initialized.
  @throws NoSuchAlgorithmException    if device is not compatible with RSA algorithm. RSA is available since API 18.
  @throws UnrecoverableEntryException if key cannot be recovered. Probably because it was invalidated by a Lock Screen change.