TripleDES Encrypting in C# and PHP not coming out the same (PKCS7, ECB)?

后端 未结 4 1997
眼角桃花
眼角桃花 2021-01-14 11:56

I\'ve spent a couple hours now trying to figure this out, but I just can\'t get it to work. I\'ve got a C# encryption routine that I need to match in php. I can\'t change

4条回答
  •  一向
    一向 (楼主)
    2021-01-14 12:35

    It appears the C# version does not set the IV. This could be an issue if you dont know what it is because msdn says:

    The IV property is automatically set to a new random value whenever you create a new instance of one of the SymmetricAlgorithm classes or when you manually call the GenerateIV method.

    It looks like in the PHP version, you are using an IV. You could try not supplying the IV and hope the C# version also uses zeros.

    Edit: Looks like for ECB, the IV is ignored.

    You might also need to encoding the key like in the C# version using utf8-encode

提交回复
热议问题