RSA decryption error: javax.crypto.BadPaddingException: Decryption error

We are using RSA (Public - Private key) encryption / decryption with padding #PKCS1, and it is working fine when we are running the app in "Debug" mode (Xcode 12.4) or generating the Appstore build from Xcode with 11 series.

But when we are generating the Testflight/ Appstore build from Xcode 12.4 (or any other Xcode with 12 series), Server is unable to decrypt the messages and throwing "RSA decryption error: javax.crypto.BadPaddingException: Decryption error".

Is there any changes in difference b/w Debug and Release mode, or this is an issue with Xcode 12.4?

Any help is welcome :)

Problems like this are almost always caused by a bug in your code. Specifically, if your code is relying on undefined behaviour and the optimisations applied to your Release build change that behaviour, you’ll see exactly this problem. This is especially true when working with crypto APIs; these APIs use a lot of unsafe pointers [1], and it’s easy to get that code wrong.

A good way to debug this is to (temporarily) add code that logs the inputs and outputs of each crypto operation. You can then compare the result from the Debug and Release builds.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Except Apple CryptoKit.

Thanks for your response Eskimo. 

I have already logs and compare the input before encryption in both Debug and release builds and both are same. This issue is happening only when doing the encryption in release builds.   I have tried this RSA utilities as well but getting same error. https://github.com/btnguyen2k/swiftutils

I have already logs and compare the input before encryption

OK, but what about the output after encryption?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I seem to have encountered the same problem. In the release mode, RSA encrypts a string of ciphertext that cannot be decrypted

I seem to have encountered the same problem.

I recommend that you start a new thread with the details. Tag it with Security so that I see it. And feel free to reference back to this thread if you think that any of the details here are relevant to your problem.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

RSA decryption error: javax.crypto.BadPaddingException: Decryption error
 
 
Q