0

I use RSA for encrypt data and send to server, and I saw a java file to find out how Android encryption works and I find the padding that Android uses: "RSA/ECB/OAEPWithSHA-1AndMGF1Padding".

I use SwiftyRSA pod and I have .OAEP padding and I encrypt the data but the server can not decrypt.

I use a website (devglan.com) for online encrypt and decrypt for testing.

The situation is that:

  1. I can encrypt data with this website and decrypt on server,
  2. I can encrypt data in my app and decrypt in website (not server)
  3. when I encrypt data in my app, the server can't decrypt data

I checked with server guy and they showed me the result of decrypt and it was null. I sent data with Postman for test and the response was successful.

My encryption code is:

let PublicKey = try! PublicKey(base64Encoded: PublicKeyString)
let clear = try! ClearMessage(string: "my text", using: .utf8)
let encrypted = try! clear.encrypted(with:publicKey1, padding:.OAEP)
     
let data = encrypted.data
let EncodeBase64Data = data.base64EncodedString()
Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
  • 1
    *...server can not decrypt...* How do you know it can't decrypt? What is your evidence? If there is an error or an exception please edit your question to include that error or exception stacktrace. If there is some other behavior that seems wrong or unexpected please describe that behavior. If possible, please provide complete inputs, parameters, and outputs that trigger the problem. In this case, since one of those parameters is a private key, you must make that a throwaway test key that you never use for anything else besides this example. – President James K. Polk Nov 14 '20 at 13:49
  • Currently we do not have enough data to help you with this question as James indicated. I'd at least expect the decryption code, a private key and of course the ciphertext as you receive it on the server. I've helped you format the question given the many edits that you've already tried to perform. Maybe have a look yourself by hitting the [edit] button once more or clicking the link here; I'd prefer Markdown over HTML, it's much easier. – Maarten Bodewes Nov 14 '20 at 14:29

0 Answers0