skip to Main Content

I’m beginner level android developer & new to encryption. I created an app which loads PDFs from Firebase to android activity based on subscription. I implemented all verification methods.

But I don’t want to load my PDFs in some reverse engineered or tampered app. I will encrypt all the PDFs on my own and save in firebase. I’m going to use OpenSSL library to encrypt.. I want my original app which user installed from play store should be able to decrypt it. I found about KeyStore in Android.

How to store the encryption key in keystore android so user can decrypt the PDF file and cannot be easily accessed if reverse engineered?

Please help me. It’s very important to me.

2

Answers


  1. I’m about to delete my answer:

    What is the code, in Java or Kotlin, that you’ve used to decrypt incoming PDFs from your database? There’s plenty of wonderful tutorials online with similar code so don’t be shy.

    I’d love to help.

    Login or Signup to reply.
  2. Here’s how you can use the KeyStore to store your encryption key securely:

    KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
    KeyGenParameterSpec keySpec = new KeyGenParameterSpec.Builder(keyAlias, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT).setBlockModes(KeyProperties.BLOCK_MODE_CBC).setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7).setKeySize(256).build();
    keyGenerator.init(keySpec);
    SecretKey secretKey = keyGenerator.generateKey();
      
    KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
    keyStore.load(null);
    
    KeyStore.SecretKeyEntry keyEntry = new KeyStore.SecretKeyEntry(secretKey);
    keyStore.setEntry(keyAlias, keyEntry, null);
    KeyStore.SecretKeyEntry keyEntry = (KeyStore.SecretKeyEntry) keyStore.getEntry(keyAlias, null);
    SecretKey retrievedKey = keyEntry.getSecretKey();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search