I worked on a mobile registration flow that encrypted a password with an RSA public key before sending it to the backend. The client parsed a PEM key, encrypted the input, and encoded the ciphertext for transmission.
The integration raised three questions: which threat does the encryption address, how is the key trusted, and what happens to the password after decryption? Answering them defines the protection the design can provide.
Separate transport, application encryption, and storage
HTTPS protects data in transit between the client and the TLS endpoint. Application-level encryption can serve a separate purpose when a system has a specific requirement, but it does not replace authenticated transport or prevent a compromised client from reading input before encryption.
RSA encryption is reversible with the corresponding private key. That is appropriate when the server needs to decrypt a protected message; it is not the normal way to store login passwords. The server should use a suitable salted password-hashing scheme. OWASP’s password storage guidance explains the distinction.
The application server remains an endpoint with access to the plaintext when it decrypts the payload. Any description of end-to-end protection needs to identify the endpoints and account for that access.
Know which key is allowed where
The public key may be distributed to the client. Keep the private key in a protected backend key-management system and out of the app bundle and source repository.
Distributing a public key still requires authentication. If a client obtains a replacement key, it needs a trusted channel or validation mechanism. Otherwise, an attacker who substitutes a key can defeat the purpose of encrypting to the intended server.
Rotation also needs a protocol. A key identifier can help the server select the right active key while older clients are still in use. Retiring a key requires understanding which clients and messages depend on it.
Make the cryptographic parameters explicit
RSA cannot encrypt arbitrarily large payloads. RFC 8017 defines the OAEP message limit in terms of the modulus length and hash output length. Splitting a long value into improvised RSA chunks is not a sound default design; established hybrid encryption uses asymmetric cryptography to protect a symmetric key and authenticated encryption for the data.
For an RSA requirement, the client and server must agree on padding, the OAEP hash, the mask-generation function parameters, and any label. OWASP’s cryptographic storage guidance discusses randomized padding and suitable primitives. Specify those parameters explicitly in the protocol and library configuration.
This illustrative pseudocode shows the encryption boundary and the protocol decisions it depends on:
encryptForServer(plaintext, publicKey, keyId):
validate configured key and supported parameters
ciphertext = vettedLibrary.rsaOaepEncrypt(plaintext, publicKey)
return { keyId, ciphertext: base64(ciphertext) }
Base64 is an encoding, not encryption. It makes bytes convenient to transport without adding confidentiality.
Review logs alongside encryption
An earlier helper example included plaintext and ciphertext debug logging. Those statements expose sensitive input and need to be removed before using real credentials, including during development.
Removing the print is necessary, but the review should also inspect interceptors, exception reports, analytics, and server logs. A safe encryption helper can still feed an unsafe request logger.
I would log the operation’s result and a non-sensitive correlation ID. That is enough to connect a failure with a request without exposing the credential.
Test the protocol and its failure cases
Useful tests include malformed keys, unsupported parameters, oversized input, key rotation, Unicode input, and agreement with the server implementation. They should also verify that failures do not expose the value being encrypted.
Reviewing the integration required following the password through the whole flow. Key trust, padding, transport, logging, and server storage each determine what the encryption actually protects.