Encryption in sending data from one app to another in android

喜你入骨 提交于 2020-04-16 02:27:23

问题


I want to send sensitive data from one app to another.

I use Intent and send data via Bundle. Now, I am supposed to use an encryption algorithm to encrypt the data to send and parallelly the receiver app will decrypt the data.

Which algorithm is best suited for the mobile platform?

I have gone through RSA documents suggests that it is not suggested for long text encryption.

I have seen the algorithm uses a random key generation method which will cause an issue in my case as both the app need to share the same key to encrypt and decrypt.


回答1:


I have gone through RSA documents suggests that it is not suggested for long text encryption.

true

Depending in the key length, e. g. 2048 key with pkcs#1.5 padding is intended to encrypt maximum if 245 bytes. Some implementation frameworks enforce even less (144 bytes,..)

I have seen the algorithm uses a random key generation method which will cause an issue in my case as both the app need to share the same key to encrypt and decrypt.

Actually - it's a combination of the both ways what is commonly used. see hybrid cryptosystem

Basically - each app has its own keypair and the apps share the public keys of the destination parties. You can use a random key for data encryption and rsa to encrypt the data key. Then feel safe to use Intend and Bundle to move the encrypted data and encrypted key.

It may be a good baseline to start with.

Edit:

I need to send data from my one app(A) to another(B). So, A will encrypt the data and will send the data to B with encryption (key is generated in app A).

If you send an encryption key (let's call it data key) along data in plain, anyone intercepting the traffic (intent or bundle) would be able to decrypt the data. So that's where the RSA comes into the game. You can encrypt the data key the way only B can decrypt it

Now B has to decrypt the data. If the new code of key generation will be written in app B then it will create different key and hence will not be able to decrypt....

Try to search and learn how an asymmetric cipher (RSA) works. The full description is outside scope of the question, you may ask another one what is not clear in it.

Basically - app B needs to create a keypair (public and private key). The public key is used for encryption, the private key is for decryption. A needs to get the public key of B to encrypt the data key. How you get the public key from B to A is up to you (shared storage, configure in an app, ..)

You want to pass encrypted data without sharing a common secret between apps, then RSA is a way to go.



来源:https://stackoverflow.com/questions/60634550/encryption-in-sending-data-from-one-app-to-another-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!