Can we Encrypt a folder in android?
Actually I am new to android. Can we encrypt a folder which contains sub folders and files in sdcard and decrypt it back ?
开发者_运维技巧Any Help will be greatly appreciated.
Thank you.
How new are you to Java in general? You can use all the javax.security
and javax.crypto
classes (like Cipher
) in Android to provide data encryption/decryption.
Keep in mind that files on the SD card can be accessed by the user directly (either by mounting on a PC and exploring or through File Manager apps), which means there is a chance that, while they may not be able to read the data in the file, a user could theoretically delete the directories you create there if they so choose...and that may not be kosher for your application.
Also, there really is no way to simply set up a folder as "encrypted" and automatically have any file there be protected for you. You would need to create the directory you want to use, and then encrypt/decrypt each file as you write/read the data.
Hope that helps!
If you're trying to encrypt data private to your application, and not the user, then you would need access to a key/token/nonce to unencrypt. Unless you're doing the encryption remotely or using the Android NDK it would be trivial to obtain the key/token/nonce and unencrypt it. Apk's aren't compiled and can easily be unpackaged and the source viewed.
You certainly can encrypt and decrypt data on Android as explained in the other answers. But consider the "doing" gets more complicated.
1) Use DES and a 56 bit key and you do not need an export license in the US. Use AES or TDES with 128 or 256 bit key and you may need to start filling out the paperwork :)
2) Unless you want the user to enter a passphrase exactly equal to the key size you may want to seed and then multi hash the passphrase using say SHA256.
3) You may need to encode the cipher data into a 64 bit character set (letters upper and lower case, numbers,+ and /) as cipher text. This usually takes groups of three bytes, expands them to four bytes with = as a pad when needed. Just search the internet for base64 encode decode algorithms.
4) You may want to add a LEVEL OF INDIRECTION into the scheme so that the user can change the password at a later date WITHOUT changing the file symmetric key. So there are two encryptions, encrypting the file with a random symmetric key and then encrypting the random symmetric key with the users passphrase. UGH.
精彩评论