cordova-plugin-crypto-file icon indicating copy to clipboard operation
cordova-plugin-crypto-file copied to clipboard

BUG Defining cryptfiles.include encrypts files but does not decrypt them

Open sc0ttdav3y opened this issue 3 years ago • 1 comments

Describe the bug

Following the README, I've added the following to plugin.xml so I can support json files being encrypted.

    <cryptfiles>
        <include>
            <file regex="\.(htm|html|js|css|json)$" />
        </include>
        <exclude>
        </exclude>
    </cryptfiles>

During build-time I see the files here are encrypted, but at run-time they are not decrypted. The reason is the DecryptResource.java class is not getting updated with the file regex, and it still has the default list:

  private static final String[] CRYPT_FILES = {
    ".htm",
    ".html",
    ".js",
    ".css",
  };

I see code in after_prepare.js that intends to change the class, but it is targeting INCLUDE_FILES and EXCLUDE_FILES properties in the Java source, rather than CRYPT_FILES which is in the source here:

https://github.com/PeterHdd/cordova-plugin-crypto-file/blob/348a65aea6183226bd31f3d6bdb2ac68ed05cd4f/src/android/com/crypt/cordova/DecryptResource.java#L31.

My workaround is to manually edit the Java class to add the extension.

To Reproduce

Steps to reproduce the behavior:

  1. add a custom extension into plugin.xml as above
  2. compile an app that requires a file of that type

Expected behavior

The app should decrypt the read when it is called.

Additional information

I notice that the original plugin cordova-plugin-crypt-file does have INCLUDE_FILES and EXCLUDE_FILES, so it's possibly just a back-porting issue:

https://github.com/tkyaji/cordova-plugin-crypt-file/blob/ddee9dfcbf082c417a41b8480f7a9d2b7884ed87/src/android/com/tkyaji/cordova/DecryptResource.java#L29

sc0ttdav3y avatar Oct 04 '21 04:10 sc0ttdav3y

Here's a PR that fixes this: https://github.com/PeterHdd/cordova-plugin-crypto-file/pull/21

sc0ttdav3y avatar Oct 04 '21 05:10 sc0ttdav3y