{"id":212809,"date":"2025-12-27T01:57:13","date_gmt":"2025-12-27T01:57:13","guid":{"rendered":"https:\/\/www.newsbeep.com\/ie\/212809\/"},"modified":"2025-12-27T01:57:13","modified_gmt":"2025-12-27T01:57:13","slug":"securing-legacy-android-apps-modern-encryption-practices","status":"publish","type":"post","link":"https:\/\/www.newsbeep.com\/ie\/212809\/","title":{"rendered":"Securing Legacy Android Apps: Modern Encryption Practices"},"content":{"rendered":"<p>As software engineers rise up the ranks from junior levels to managerial roles in <a href=\"https:\/\/thenewstack.io\/intertwined-worlds-platform-and-mobile-app-engineering\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">mobile development<\/a>, <a href=\"https:\/\/thenewstack.io\/why-quality-code-matters-and-how-to-achieve-it\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">good code practices<\/a> become more apparent and not just an afterthought. One of the litmus tests of seniority is the ability to adapt to modern security practices.<\/p>\n<p>It is worth noting that as the mobile ecosystem moves fast, attacks on user data also evolve at the same pace. Therefore, it is the engineer\u2019s responsibility to modernize the remnants of legacy implementations, even if they still appear to work. That\u2019s because they expose users to security threats and render applications susceptible to attacks.<\/p>\n<p>Some of the security debt often hidden beneath old code include, but are not limited to:<\/p>\n<p>Use of <a href=\"https:\/\/www.okta.com\/identity-101\/md5\/#:~:text=The%20message%2Ddigest%20algorithm%20MD5,matched%20with%20a%20public%20key.\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">MD5 <\/a>or<a href=\"https:\/\/www.nist.gov\/news-events\/news\/2022\/12\/nist-retires-sha-1-cryptographic-algorithm\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\"> SHA-1<\/a> for hashing passwords or verifying data integrity.<br \/>\nReliance on <a href=\"https:\/\/www.geeksforgeeks.org\/computer-networks\/data-encryption-standard-des-set-1\/\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">DES<\/a> or <a href=\"https:\/\/www.npmjs.com\/package\/aes-ecb\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">AES\/ECB<\/a> for encryption (both prone to predictable patterns).<br \/>\nHardcoded API keys or symmetric keys stored in SharedPreferences instead of the Android Keystore System.<br \/>\nOutdated authentication flows, such as Basic Auth or custom token handling.<br \/>\nUse of deprecated and <a href=\"https:\/\/www.appmarq.com\/public\/tqi,1039044,Avoid-usage-of-BannedAPI-when-using-ESAPI-library\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">ESAPI-banned API<\/a>, such as android.webkit.WebView.setJavaScriptEnabled(true) and Math.Random.*<br \/>\nNon-compliance with the most recent OWASP Top 10 lists.<\/p>\n<p>A typical security scan of a mobile application by AppSec tools, such as Checkmarx, will more often reveal the above practices, all of which were once common but are now considered dangerous.<\/p>\n<p>Let\u2019s explore shared legacy cryptographic algorithms and their modern equivalents.<\/p>\n<p>The Dangers of Weak Hash Algorithms (MD5 and SHA-1)<\/p>\n<p>MD5 and SHA-1 are cryptographic hash functions known for their vulnerabilities, including susceptibility to collision attacks. A cryptographic hash function takes any input, which can be a message, file or password, producing a short and unique fingerprint of that data. A collision attack occurs when two distinct inputs produce the same hash, leading to identity spoofing, <a href=\"https:\/\/thenewstack.io\/how-iam-missteps-cause-data-breaches\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">tampering with signed data and other security breaches<\/a> by attackers through reverse-engineering or hash manipulation.<\/p>\n<p>These algorithms have been broken publicly for years. MD5, collisions can be generated in milliseconds on consumer hardware. A key vulnerability: SHA-1 was officially deprecated after <a href=\"https:\/\/thehackernews.com\/2017\/02\/sha1-collision-attack.html#:~:text=The%20Google%2Dled%20attack%20on%20SHA1%2C%20dubbed%20SHAttered%2C,attackers%20to%20break%20communications%20encoded%20with%20SHA1.\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">Google\u2019s SHAtteredattack in 2017<\/a>. Over time, cryptanalysis has shown that SHA-1 is no longer secure enough for use in sensitive applications.<\/p>\n<p>Additionally, continuous use of these algorithms for password storage, signature generation or integrity checks can lead to non-compliance with regulatory bodies such as EU data privacy laws GDPR, the global payment card industry security standard PCI-DSS and others.<\/p>\n<p>Alternatives for Data Integrity and Password Hashing<\/p>\n<p>Therefore, to secure your legacy application, consider replacing the above vulnerable algorithms with the following:<\/p>\n<p>For data integrity, instead of using an MD5 checksum, consider a more secure cryptographic hash function, such as <a href=\"https:\/\/www.movable-type.co.uk\/scripts\/sha256.html\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">SHA-256<\/a> or <a href=\"https:\/\/csrc.nist.gov\/projects\/hash-functions\/sha-3-project\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">SHA-3<\/a>. They offer stronger resistance to collision and pre-image attacks. Using SHA-256 or SHA-3 also guarantees determinism by ensuring the same input always gives the same hash, while ensuring that even a tiny input change results in a significant change in output. This avalanche effect helps to detect even the slightest one-bit tampering or corruption.<\/p>\n<p>When it comes to password storage and hashing, consider an algorithm that not only provides data integrity but also ensures confidentiality. This is where MD5 and SHA-1 fail. These cryptographic hash functions are designed for integrity and speed, but never for secure password storage. Additionally, the hashes are always stored by adding salt, making them prone to rainbow table attacks.<\/p>\n<p>To overcome this, consider using security-focused algorithms such as <a href=\"https:\/\/auth0.com\/blog\/hashing-in-action-understanding-bcrypt\/\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">bcrypt<\/a>, <a href=\"https:\/\/argon2.online\/\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">Argon2<\/a> or <a href=\"https:\/\/hexdocs.pm\/pbkdf2_elixir\/Pbkdf2.html\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">PBKDF2<\/a>. These are not just hash algorithms but key derivation functions (KDFs), which are engineered to resist brute-force and GPU attacks.<\/p>\n<p>Password-Based Key Derivation Function 2 (PBKDF2) is one of the most widely used KDFs and is approved by the National Institute of Standards and Technology (NIST). PBKDF2 strengthens the security of hashed passwords by adding a salt to the pre-hashed password, ensuring that the same password produces a different hash. This approach defeats the rainbow table attacks. PBKDF2 also applies many iterations of the hashing process, known as stretching. Stretching implies multiple applications of the hash function (thousands or even millions of times) to the password and salt combination. This approach slows the hash computation, thereby reducing the feasibility of brute-force attacks.<\/p>\n<p>PBKDF2 is limited in the number of salts it can generate, so it is the engineer\u2019s responsibility to generate and store salts separately. It is this limitation that makes bcrypt a preference for many. With built-in and automatic salt handling, bcrypt is considered more secure due to resistance to GPU cracking.<\/p>\n<p>It is older, CPU-intensive and simpler to implement. This makes it a reasonable choice for less demanding applications or legacy applications, but it is not the sharpest tool available. For this, Argon2 is the double-edged \u201cHonjo Masamune\u201d sword.<\/p>\n<p>Argon2 is a modern, secure KDF designed to protect passwords by being memory-hard, which means it requires more memory resources. This makes brute-force attacks using fast hardware, such as GPUs, much less efficient and more costly. It is also highly configurable, enabling fine-tuning of security parameters such as memory usage, iterations and parallelism \u2014 making it resistant to evolving cracking techniques.<\/p>\n<p>It is worth mentioning that KDFs should be implemented on the backend server for password storage, as hashing on the client-side (Android) is insecure against server compromise.<\/p>\n<p>Vulnerabilities of DES and AES\/ECB Encryption<\/p>\n<p>Other than the above, if your application uses symmetric encryption as an alternative, replace AES\/ECB or DES with <a href=\"https:\/\/medium.com\/@pravallikayakkala123\/understanding-aes-encryption-and-aes-gcm-mode-an-in-depth-exploration-using-java-e03be85a3faa\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">AES\/GCM<\/a>. Symmetric encryption is one of the two fundamental pillars of modern cryptography, alongside public-key (asymmetric) encryption. In symmetric encryption, the same key is used for both encryption and decryption. It is also widely used in modern mobile development, ranging from file encryption and token storage to secure preferences.<\/p>\n<p>The Advanced Encryption Standard (AES) replaced the deprecated Data Encryption Standard (DES), a 56-bit symmetric cipher from the 1970s. DES has a very small keyspace, making it easy to brute-force.<\/p>\n<p>AES\/ECB (Electronic Codebook) has a fundamental weakness of pattern exposure. By design, AES\/ECB divides plaintext into fixed-size blocks and encrypts each block independently with the same key. As simple as it is, it is considered insecure because the same plaintext blocks produce the same ciphertext blocks, hence leaking patterns.<\/p>\n<p>Modern Symmetric and Asymmetric Encryption Alternatives<\/p>\n<p>The modern and secure alternatives include:<\/p>\n<p><a href=\"https:\/\/www.cincopa.com\/learn\/what-is-cipher-block-chaining-cbc-mode-in-aes#:~:text=Mode%20in%20AES?-,Cipher%20Block%20Chaining%20(CBC)%20is%20a%20block%20cipher%20mode%20of,if%20plaintext%20contains%20repetitive%20patterns.\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">AES\/CBC<\/a> (Cipher Block Chaining), where each plaintext block is <a href=\"https:\/\/www.youtube.com\/watch?v=h7Cgx-pn9bw\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">XORed<\/a> with the previous ciphertext block before being encrypted, causing a chaining effect. The first block must also have a unique initialization vector (IV).<\/p>\n<p><a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc5288#:~:text=Abstract%20This%20memo%20describes%20the,Hellman%2Dbased%20key%20exchange%20mechanisms.\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">AES-GCM<\/a> (Galois\/Counter Mode) is the modern, integrity-centered and recommended mode of symmetric encryption on Android and in most secure systems today. It operates by incrementing a counter and XORing the result with the plaintext. GCM is an <a href=\"https:\/\/developers.google.com\/tink\/aead\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">Authenticated Encryption with Associated Data (AEAD)<\/a> mode, meaning it provides both confidentiality and integrity in a single efficient step.<\/p>\n<p>It is crucial to make sure that the symmetric keys are not hard-coded or stored in insecure locations such as SharedPreferences. Instead, use Android Keystore System which stores keys in an isolated and non-exportable way and using the Cipher class with the correct transformation string (such as AES\/GCM\/NoPadding).<\/p>\n<p>Asymmetric encryption (public-key encryption), on the other hand, is too slow to be used for <a href=\"https:\/\/thenewstack.io\/how-time-plays-a-crucial-role-in-aggregating-mobile-data\/\" class=\"local-link\" rel=\"nofollow noopener\" target=\"_blank\">bulk data on mobile applications<\/a>. It is primarily used to supplement symmetric encryption in a hybrid approach to secure the exchange of AES symmetric keys and to support digital signatures for authentication and data integrity. <a href=\"https:\/\/www.geeksforgeeks.org\/computer-networks\/rsa-algorithm-cryptography\/\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">RSA (Rivest-Shamir-Adleman) <\/a>relies on the difficulty of factoring large prime numbers. It uses a public key for encryption and a private key for decryption.<\/p>\n<p>For public-key encryption, consider <a href=\"https:\/\/www.cs.rit.edu\/~spr\/COURSES\/CRYPTO\/oaep.pdf\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">RSA\/OAEP (Optimal Asymmetric Encryption Padding<\/a>) or <a href=\"https:\/\/blog.cloudflare.com\/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography\/\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">ECC (Elliptic Curve Cryptography)<\/a> instead of RSA\/ECB\/PKCS1, which lack modern cryptographic guarantees. The padding scheme (PKCS1) used in RSA\/ECB\/PKCS1 is the leading cause of the vulnerability, as it is obsolete, lacks modern security proofs and is susceptible to chosen-ciphertext attacks. OAEP padding eliminates these vulnerabilities by adding randomness and using hash functions.<\/p>\n<p>For signing or certificate purposes, consider transitioning to stronger algorithms, such as RSA with SHA-256 or <a href=\"https:\/\/www.cs.miami.edu\/home\/burt\/learning\/Csc609.142\/ecdsa-cert.pdf\" class=\"ext-link\" rel=\"external  nofollow noopener\" onclick=\"this.target=&#039;_blank&#039;;\" target=\"_blank\">ECDSA (Elliptic Curve Digital Signature Algorithm)<\/a>. When it comes to Android security and other resource-limited environments, ECDSA is highly favoured because it can produce smaller and faster-processing keys, which is important for TLS\/SSL communication.<\/p>\n<p>Additionally, to secure the certificates and build trust during the communication between applications and the server over TLS\/SSL, consider certificate pinning. It adds a layer of security by ensuring that the application only trusts specific, preset certificates or public keys, which is a crucial defence against man-in-the-middle (MITM) attacks.<\/p>\n<p>Conclusion<\/p>\n<p>Migrating to modern cryptography should be a canary process that involves a clear audit of legacy algorithm use, risk classification, compatible migration and, finally, intensive testing and verification. All these processes should also involve clear documentation of the project blueprint for future development.<\/p>\n<p>\t<a class=\"row youtube-subscribe-block\" href=\"https:\/\/youtube.com\/thenewstack?sub_confirmation=1\" target=\"_blank\" rel=\"nofollow noopener\"><\/p>\n<p>\n\t\t\t\tYOUTUBE.COM\/THENEWSTACK\n\t\t\t<\/p>\n<p>\n\t\t\t\tTech moves fast, don&#8217;t miss an episode. Subscribe to our YouTube<br \/>\n\t\t\t\tchannel to stream all our podcasts, interviews, demos, and more.\n\t\t\t<\/p>\n<p>\t\t\t\tSUBSCRIBE<\/p>\n<p>\t<\/a><\/p>\n<p>    Group<br \/>\n    Created with Sketch.<\/p>\n<p>\t\t<a href=\"https:\/\/thenewstack.io\/author\/stephen-henry\/\" class=\"author-more-link\" rel=\"nofollow noopener\" target=\"_blank\"><\/p>\n<p>\t\t\t\t\t<img decoding=\"async\" class=\"post-author-avatar\" src=\"https:\/\/www.newsbeep.com\/ie\/wp-content\/uploads\/2025\/12\/2a15df1a-cropped-eee864b7-stephen-henry1.jpg\"\/><\/p>\n<p>\n\t\t\t\t\t\t\tStephen Henry is a mobile engineer and a technologist at Andela. Stephen is highly experienced in mobile application development, with a specialized focus on iOS and Android platforms. He is skilled in various programming languages including Swift, Kotlin and Java,&#8230;\t\t\t\t\t\t<\/p>\n<p>\t\t\t\t\t\tRead more from Stephen Henry\t\t\t\t\t\t<\/p>\n<p>\t\t<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"As software engineers rise up the ranks from junior levels to managerial roles in mobile development, good code&hellip;\n","protected":false},"author":2,"featured_media":212810,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[110850,61,60,48853,80],"class_list":["post-212809","post","type-post","status-publish","format-standard","has-post-thumbnail","category-technology","tag-andela","tag-ie","tag-ireland","tag-post-contributed","tag-technology"],"_links":{"self":[{"href":"https:\/\/www.newsbeep.com\/ie\/wp-json\/wp\/v2\/posts\/212809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.newsbeep.com\/ie\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.newsbeep.com\/ie\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.newsbeep.com\/ie\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.newsbeep.com\/ie\/wp-json\/wp\/v2\/comments?post=212809"}],"version-history":[{"count":0,"href":"https:\/\/www.newsbeep.com\/ie\/wp-json\/wp\/v2\/posts\/212809\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.newsbeep.com\/ie\/wp-json\/wp\/v2\/media\/212810"}],"wp:attachment":[{"href":"https:\/\/www.newsbeep.com\/ie\/wp-json\/wp\/v2\/media?parent=212809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.newsbeep.com\/ie\/wp-json\/wp\/v2\/categories?post=212809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.newsbeep.com\/ie\/wp-json\/wp\/v2\/tags?post=212809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}