1

I have the encrypted password function at Android java function and Decrypt function at C# side. My problem is when I encrypt the password

Password is
No8ANfBX/0GAWJnF4v0bQwf/4UiJ7qY7rOPfrfB0XMQ=

When I pass this parameter via Rest API, My password changed to-

No8ANfBX/0GAWJnF4v0bQwf\/4UiJ7qY7rOPfrfB0XMQ= Image

So when decrypt at server,password is not same. My code for parameter pass is

public JSONObject A(String userName, String passWord, String version) throws Exception {
    JSONObject result = null;
    JSONObject o = new JSONObject();
    JSONObject p = new JSONObject();
    try {
        o.put("interface", "AA");
        o.put("method", "A");
        p.put("userName", mapObject(userName));
        p.put("passWord", mapObject(passWord));
        p.put("version", mapObject(version));
        o.put("parameters", p);
        Log.e("Pass",String.valueOf(passWord));
        Log.e("Pass",String.valueOf(mapObject(passWord)));
        String s = o.toString();
        Log.e("Params", String.valueOf(s));
        String r = load(s);
        Log.e("Params", String.valueOf(r));
        result = new JSONObject(r);
    } catch (Exception e) {
        Log.e("Error is", String.valueOf(e));
    }
    return result;
}

How could I change not to add extra \ in params?

H H
  • 263,252
  • 30
  • 330
  • 514
Sabai Phoo
  • 358
  • 1
  • 4
  • 20
  • 1
    Its just escaping the special character `/`. For that is used the reverse bar `\`, just delete all the reverse bars from the string in the server and thats all. Clean the string. – Ivan Aug 12 '19 at 07:10
  • Yes how could I do from android java params pass not to change from No8ANfBX/0GAWJnF4v0bQwf/4UiJ7qY7rOPfrfB0XMQ= to No8ANfBX\/0GAWJnF4v0bQwf\/4UiJ7qY7rOPfrfB0XMQ= – Sabai Phoo Aug 12 '19 at 07:14
  • 1
    Is the `'\\'` really there or are you just seeing it in the debugger? – H H Aug 12 '19 at 08:33
  • There are a couple things to unpack here and I don't see enough info in the question to do so. First, it appears what you call the password is already encrypted and base64 encoded. I say this because when I base64 decode it I get a nice length (32 bytes) of random-looking bytes. Second, where is this "decrypted password at the server" coming from? Where is that code? – President James K. Polk Aug 12 '19 at 12:29

1 Answers1

1

You need to pass your password with UTF-8 formate & also decrypt from server end with UTF-8 So it would be like URLEncoder.encode("No8ANfBX/0GAWJnF4v0bQwf/4UiJ7qY7rOPfrfB0XMQ=", "utf-8")

Sanjay Bhalani
  • 2,424
  • 18
  • 44
  • Wouldn't you use [`Encoding.UTF8`](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.utf8?view=netframework-4.8) for that? Either use [`GetBytes`](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytes?view=netframework-4.8) on that directly, or if you really want/need to use the `URLEncorder` you can pass `Encoding.UTF8` instead of `"utf-8"`. – Joelius Aug 12 '19 at 07:28
  • 2
    This is not an UTF8 related problem. – H H Aug 12 '19 at 08:29
  • @Pal try this one for C# https://stackoverflow.com/questions/14057434/how-can-i-transform-string-to-utf-8-in-c – Sanjay Bhalani Aug 12 '19 at 08:45