In Android how to decrypt a text file present in resource folder and use the data in it. So that i can maintain a encrypted file inside the resource folder in that apk. Help me to get this.
Take a look at the javax.crypto.Cipher packages.
Example here:
Android File Cryptography
Related
I'm using the EncryptedFile class which is part of the Android Jetpack library and introduced in Google I / O 19. I just want to know if this library only encrypts a .txt file or any type of file such as a farmware file. , Image file, video file or any large file can be encrypted.
As mentioned here, it seems to be used for creating or reading a previously encrypted file. No such limitation to *.txt files is mentioned.
You can always try more and more files to discover it even further!
After searching for solution, I have found from this link that it is possible to retrieve path like:
Using Resource Id
Syntax : android.resource://[package]/[resource_id]
Example : Uri.parse("android.resource://com.my.package/" + R.raw.mp3filename);
Which is exactly what I want. Problem is that, I'm using lolipop, and it does not work. When the package/resource is parsed, path from Uri.parse will be null. Is there other way around to write this, since in my Song class, I have only access to resourceId (R.raw.mp3filename).
Is it possible to get file path by using R.raw.mp3file
No, because it is not a file on the device. It is a file on the hard drive of your development machine. On the device, it is merely an entry in an APK file.
Either:
Do whatever you are trying to do some other way that does not involve a file path, or
Use openInputStream() on a Resources object (you can get one from any Context via getResources()), and use Java I/O to copy the contents of that resource to a local file, such as on internal storage
I have code for creating an internal file, there is random algorithem that create the data stored in it and i want any app to have the same file with the same binary data in it.
so i need to make the file on my desktop and add it to internal files some how.
my question is what do you think is the best way to do it.
i thought to locate it in my project, read it, and write it to internal files.
the problem is, i dont know where to locate my file in android studio so that it will be included in the external files and then where to read it from.
thanks. =]
hope i made myself clear.
Put it in src/main/assets/.
You can then access your file with AssetManager and do whatever you want with it.
From the Android Developers website:
main/assets/
This is empty. You can use it to store raw asset files. Files that you
save here are compiled into an .apk file as-is, and the original
filename is preserved. You can navigate this directory in the same way
as a typical file system using URIs and read files as a stream of
bytes using the AssetManager. For example, this is a good location for
textures and game data.
You need to move that into the assets folder. From there you can refer to the file.
I am currently working on a project that involves ssl communication. So, I want to copy my bks file to the device' s internal memory and access it afterwards. I am using a specific library for communication and I have to provide the bks file' s full path as a parameter to this library. Where should I put this bks file? Into the raw or assets folder or somewhere else? From which uri can I access this file? (In windows I am giving it C:\keys\blah.bks, so I have to give a similar uri like /data/data/com.example.exampleapplication/my_app/blah.bks or something like this.) How is this achieved in Android system?
Thanks in advance
Store it in the assets folder of your app.
but consider encrypting it and letting your program decrypt it, since files in the assets folder are user accessible
My android application is configurable using an external XML file present in the SD Card. The changes in the configuration requires a new XML file to be copied in that location. This XML file needs to be encrypted. So if the user request a new config for the app, the steps would be:
New XML file is generated for desired configuration.
File is encrypted using some standard encryption utility.
The file is sent to client/user.
Client copies the file to SD Card, and starts my app.
My application opens the file, decrypt it, read the content and delete the file.
I need help in step 2 and 5. Which standard tool I can use to encrypt my XML file (Should use some standard encryption algo) and secondly how the file can be decrypted in my android app. I am looking into java crypto package.
You can use this:
Android encryption
Beware as you should salt your encryption key with something not stored on the app (coming from a server for example) so that by reverting the APK to code you couldn't read the file anyway.