Skip to content

Instantly share code, notes, and snippets.

@dudego
Created March 11, 2021 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dudego/7e64d958b554a16131e2cbfa7602290b to your computer and use it in GitHub Desktop.
Save dudego/7e64d958b554a16131e2cbfa7602290b to your computer and use it in GitHub Desktop.
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