Encryption is the process of converting data into a form that cannot be read without a special key. In mobile applications, encryption protects users’ personal data, payment information, and business logic from interception and leakage. According to Statista (2024), the number of data breaches from mobile apps increased by 38% over two years, and in 72% of cases the cause was missing or incorrect encryption. Modern mobile platforms provide built-in APIs for encryption, and their use is a mandatory security standard. Statista, 2024
Key Takeaways
Encryption in the context of mobile applications is the application of cryptographic algorithms to protect data stored on the device (data at rest) and transmitted over the network (data in transit). At the device level, local storage is encrypted: files, databases, SharedPreferences, and cache. At the network level, traffic between the app and the server is encrypted via TLS/HTTPS protocols. The ultimate goal is to ensure that even with physical access to the device or traffic interception, an attacker cannot read the protected data without the cryptographic key.
Mobile devices are particularly vulnerable to data loss: a phone can easily be lost, stolen, or infected with malware. According to the Ponemon Institute (2023), 42% of companies affected by data breaches attribute incidents to mobile devices. Without encryption, an attacker can connect to the device via USB, extract the SQLite database, and read all stored data. Encryption solves this problem: even if the database is extracted, its contents remain encrypted. Additionally, the US and EU have laws (GDPR, CCPA) requiring encryption of personal data and imposing fines of up to 4% of annual turnover for violations. Using encryption is not only a technical but also a legal necessity for any mobile application that handles user data.
All encryption algorithms fall into two main types: symmetric (one key for encryption and decryption) and asymmetric (a pair of keys — public and private). The choice of type depends on the use case: symmetric algorithms are more often used for encrypting local data due to their speed, while asymmetric algorithms are used for key exchange and authentication.
| Characteristic | Symmetric | Asymmetric |
|---|---|---|
| Number of Keys | 1 (secret) | 2 (public + private) |
| Speed | High (1–10 GB/s) | Low (1–10 MB/s) |
| Key Distribution | Problematic — key must be transmitted | Simple — public key is published |
| Examples | AES, ChaCha20 | RSA, ECDH, ECIES |
| Use in Mobile Development | Local data encryption | Key exchange, digital signatures |
In practice, mobile applications use hybrid encryption: an asymmetric algorithm (e.g., ECDH) is used for session key exchange, and all subsequent data is encrypted with a symmetric algorithm (AES or ChaCha20). This approach combines the speed of symmetric encryption with the security of asymmetric key exchange. This method is the foundation of TLS 1.3, the Signal Protocol, and Apple iMessage.
Modern mobile development uses several standardized encryption algorithms, each designed for specific tasks with its own area of application.
Encryption protects data in three key scenarios: device loss (disk and app container encryption), traffic interception (TLS/HTTPS network protocols), and server-side leakage (end-to-end encryption). Each scenario requires its own approach and tools.
Data at rest — data on the device — is encrypted via Android Keystore and iOS Keychain. On Android starting from 7.0, File-Based Encryption is used, and apps can additionally encrypt their data through EncryptedSharedPreferences and EncryptedFile from the AndroidX Security library. On iOS, all apps work by default with the Data Protection API, which encrypts files at the file system level with a key tied to the device passcode. For data in transit, TLS 1.2/1.3 with mandatory Certificate Pinning is used.
End-to-end encryption (E2E) — the highest level of data protection, where a message is encrypted on the sender’s device and decrypted only on the recipient’s device. The storage and transmission server has no access to the content — it only handles encrypted blobs. The most well-known E2E implementation for mobile applications is the Signal Protocol, which uses the Double Ratchet Algorithm in combination with X3DH (Extended Triple Diffie-Hellman) for initial key exchange. The Signal Protocol provides Perfect Forward Secrecy and future secrecy: compromising one key does not reveal previous or subsequent messages. According to a study by Carnegie Mellon University (2023), E2E encryption in messaging apps reduces the risk of communication leakage by 99.7% compared to TLS-only encryption. E2E application is mandatory for Health & Fitness and Finance apps under GDPR and HIPAA requirements. To implement E2E in your own project, it is recommended to use the Signal Protocol library (Java/Swift) or one based on Olm (Matrix protocol). When choosing an E2E solution, evaluate platform compatibility: the Signal Protocol requires support for asynchronous sending and key storage on the client, which complicates multi-device scenarios — for such cases, the Matrix Protocol with its room model may be a better choice.
Let’s look at an example of encrypting and decrypting data on Android using Jetpack Security (AndroidX Security). The library provides EncryptedFile for file encryption and EncryptedSharedPreferences for settings.
val masterKey = MasterKey.Builder(context)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()
val encryptedFile = EncryptedFile.Builder(
context,
File(context.filesDir, "secret.dat"),
masterKey,
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).build()
encryptedFile.openFileOutput(applicationContext).use { outputStream ->
outputStream.write("Sensitive user data".toByteArray(Charsets.UTF_8))
}
The MasterKey is created using AES256-GCM — the most secure symmetric encryption mode. The key is stored in the Android Keystore, isolated from the main process: even if the application is compromised, an attacker cannot extract the key. EncryptedFile uses the AES-256-GCM scheme with HKDF for key derivation and a page size of 4KB, providing a good balance between speed and security. To read data, openFileInput is used with the same parameters: the library automatically decrypts the data upon reading.
On iOS, similar functionality is provided through CryptoKit (Swift) using AES.GCM or ChaChaPoly. The key is stored in the Secure Enclave via Keychain Services. The principle is the same: keys never leave the secure hardware storage, and data is encrypted before being written to disk. This architecture complies with OWASP MASVS (Mobile Application Security Verification Standard) Level L2 recommendations for applications that handle sensitive data. In real-world projects, the combination of EncryptedSharedPreferences for tokens and EncryptedFile for user data covers 100% of local encryption scenarios. Additionally, for working with keys received from the server (e.g., ECDH session keys), Android KeyStore is used with the purpose parameter set to KeyProperties.PURPOSE_ENCRYPT, which ensures that the key can only be used for authorized cryptographic operations and is never exported from the hardware storage to RAM in plain text.
Frequently Asked Questions
AES-256 in GCM mode with key storage in hardware storage (Android Keystore / iOS Keychain) is considered the gold standard. For network traffic — TLS 1.3 with the Curve25519 elliptic curve. ChaCha20-Poly1305 is used as an alternative on devices without hardware AES.
AES is a symmetric algorithm (one key), fast, suitable for encrypting large volumes of data. RSA is asymmetric (a key pair), slow, used for key encryption and signatures, not for data. In mobile applications, AES encrypts data, RSA protects keys.
You need to encrypt confidential data: access tokens, passwords, personal information, payment data, medical records. Public data (images, content) can be left unencrypted, but it is better to store them in a protected app container.
With end-to-end encryption, data is encrypted on the sender’s device before sending and decrypted only on the recipient’s device. The server only sees encrypted data. The Double Ratchet protocol, implemented in the Signal Protocol, is the most common E2E mechanism in mobile messengers.
Technically possible, but not recommended. For on-device data, use symmetric encryption (AES-GCM) with a key from the Keystore. For the network, use TLS 1.3 with a separate set of keys and Certificate Pinning. Separation prevents both channels from being compromised if one key is leaked.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also