0

I know this question has been asked many times before, but I think my situation is unique, I have had many people attempt to help me from IRC already and still have no solution. Basically I am trying to match the encryption function from a .NET CS program http://codepad.org/4SmP1Oek , in a PHP script. So far I have come up with http://codepad.viper-7.com/JsYFPK .

I have tried various different padding options, including not adding padding(leaving it to default) and yet every time I get a different value that does NOT match the C# output.

For example,

csharp: gLbzWiVmpmDrmzfZgRaM9w==

php: vid7cv20FZ68tbkNLHv3RQ==

php with no padding added: Z+ELd8MNs2frjTBUiWYj5w==

As you can see in the csharp class the encryption values are left to default, and I am fairly certain that is CBC, with 32 byte key, 16 byte iv, and 16 byte input.

UPDATE: I have recreated the C# program and successfully gotten the same output, So I have tried changing the key to multiple different strings in the php and the cs to 16 and 32 bytes but with no luck, same problem. The code is the same as I linked above and the text is sent to the Encrypt function with no modification first, so I am starting to doubt it is a padding issue now.

UPDATE #2: I have figured out the issue, it turns out it IS because the csharp program is using a 9 byte key, however I must find out why it still works so I can match the padding in php, if I set the key to something 16 bytes in both cs and php it works fine.

djdduty
  • 274
  • 1
  • 8
  • Surprised that your C# code even runs. The key has 9 bytes, not 16, 24 or 32. – CodesInChaos Oct 17 '13 at 07:29
  • Well that isn't my CS code, it was given to me by another programmer who worked with the same software, and his method has been used until now so I have to match it, but I have made the same observation(and others), which is why I believe it to be a padding issue. – djdduty Oct 17 '13 at 17:11

1 Answers1

0

I found the problem(not the solution), it seems that in .net short keys are expanded in a weird way when using CreateEncryptor, causing this problem.

djdduty
  • 274
  • 1
  • 8