I am trying to create an app in flutter and the sample code which I have is in java.
Here is the sample java code gist https://gist.github.com/kapiljhajhria/72a22ff75e238878f539f7bb21026208
and here is my flutter code gist https://gist.github.com/kapiljhajhria/795d1a7c7cf1c76ca8e327bf8b2f51de
Here is a brief summary of what I am doing
- Generate a unique Session Key: AES Random Key 256
- Encrypt JSON data using the Session Key from step 1
- Generate SHA256 hash of JSON data
- Encrypt generated hash from step 3, using session key from step 1.
- Encrypt the session key using the public key. Public key provided as certificate.cer file. I copied the String value and added it to the class as a constant in order to make it easier to use. Not sure if this was the best approach.
- Created a POST request with 3 Parameters. As shown in the java code. I think I am doing this part correctly.
- The response which I will get will be encrypted using the session key from step 1. So i will have to decrypt that response data. Haven't reached this step yet.
I don't have access to the server where this request is being made. Since the post request is being made using web view, I can't figure out a way to get proper error from my request. All I get is web page which says "Invalid Request"
So My first guess is that I am not using public key properly to encrypt my session key. if that part is correct, then I am not encrypting the data properly or my encryption method doesn't match encryption methods used in java code the java code. Maybe the session key which I am generating is not correct.
Any help would be greatly appreciated. Thank you. If you need anything from me then please let me know.
AESMode.ecbinstead ofcbc(this is used in the java code, but that's less secure), in that case IV is not ncessary. There may be more issues, this is just the first I spotted. It would hep you having contact to the people providing the service, so you could be given internal exception (unable to decrypt? wrong parameters? ...)