PHP to Delphi and back Encryption-Decryption using Rijndael

后端 未结 2 1265
无人共我
无人共我 2020-12-17 06:55

I have problems with decrypting strings sent from PHP to Delphi using the rijndael cipher. I\'m using mcrypt on the PHP side and DCP_rijndael on the Delphi side.

At

2条回答
  •  感动是毒
    2020-12-17 07:15

    Neither your PHP nor your Delphi methods appear to specify any padding. If the default paddings are different then you will get problems. Explicitly specify PKCS7 (or PKCS5) for both.

    GregS' comment about the result of decoding Base64 is correct. You are supplying encrypted cyphertext to your decRJ() method. That will be random appearing bytes. Attempting to convert it to UTF-8 will mangle it enough that it cannot be decrypted. The incoming cyphertext must be converted from Base64 direct to a byte array. Cyphertext is not a character string, which is why it needs to be converted to Base64 to be transmitted as text. It will only be text again after it has been decrypted back to plaintext.

提交回复
热议问题