Skip to content
Advertisement

Convert php decryption function to C# responds differently result

I created a service that encrypts and stores keys using PHP. The Service returns an encrypted response to the client. The client program will need to decrypt the encrypted data. But the decrypt function I wrote in PHP responds differently in C#.

So my php Function:

JavaScript

It returns:

JavaScript

Now I have converted the above function to C #. The result is strange. My C# code:

JavaScript

It returns:

JavaScript

I can’t understand where I’m making a mistake. The letters are completely different. If I do it like this:

JavaScript

It returns:

JavaScript

Can anyone help to solve this problem?

Advertisement

Answer

The line:

JavaScript

is incorrect, you want to deal with bytes directly, not converting it to a utf-8 string.

In fact, the decoded base64 is not even a valid UTF-8 string.

Working Python port:

JavaScript

UPDATE: C#

JavaScript

Ideone

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement