Created
March 11, 2021 16:09
-
-
Save dudego/7e64d958b554a16131e2cbfa7602290b to your computer and use it in GitHub Desktop.
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
ext.encryptfile = { buildFlavor, buildVariant -> | |
def fileToBeEncryptedName = 'config.txt' //name of your file to be encrypted | |
def folder = 'confidential-file' // folder where your encrypted file is to be found def folderPath = "$project.rootDir/${folder}/${buildFlavor}/${buildVariant}/" //this will resolve file path according to build flavor and build variant String fileContents = new File("$folderPath$fileToBeEncryptedName").text // read contents of this file // encryption logic def IV = new byte[16] | |
def encryption = Encryption.getDefault(encryptKey, encryptSalt, IV) //use encryptKey and encryptSalt defined above def data = encryption == null ? "" : encryption.encryptOrNull(fileContents) | |
// create file in generated assets folder which can be packaged into the selected flavor/variant apk def file = new File("$buildDir/generated/assets/shaders/$buildFlavor/$buildVariant/$ext.outputConfigFileName") | |
if (!file.getParentFile().exists()) { | |
file.getParentFile().mkdirs() | |
} | |
if (!file.exists()) { | |
try { | |
file.createNewFile() | |
} catch (Exception e) { | |
e.printStackTrace() | |
} | |
} | |
file.write data //write encrypted data in file} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment