简体   繁体   English

使用Encrypt / Decrypt进行PHP和C#通信

[英]PHP and C# communication with Encrypt/Decrypt

I have been searching and cant find a consistent solution to my problem : 我一直在搜索,无法找到一致的解决方案来解决我的问题:

I want to encrypt something in C# and decrypt it in PHP but also be able to encrypt in PHP and decrypt in C#, using the same key on both ends. 我想在C#中加密某些内容并在PHP中解密它,但也希望能够在PHP中加密并在C#中使用两端相同的密钥解密。

All the solutions I found dont seem to work both ways, most of them only work on one language and then fail on the other, either by decrypting wrong or by blowing up the offsets. 我发现的所有解决方案似乎都无法同时使用,大多数解决方案仅适用于一种语言,然后适用于另一种语言,这可能是由于解密错误或破坏了偏移量而引起的。

I would like to use TripleDES but it isnt a requirement, just want something relatively strong for plain text communication (will either use JSON or just plain key-value pairs for complex stuff). 我想使用TripleDES,但这不是必须的,只是想要一些相对强壮的纯文本通信(对于复杂的东西,将使用JSON或仅使用简单的键值对)。

Thanks in advance 提前致谢

PS: http://pastie.org/643106 this is what I have been testing with. PS: http : //pastie.org/643106这就是我一直在测试的东西。

The most likely cause for you discrepancies is different text encodings. 造成差异的最可能原因是文本编码不同。 Since PHP is usually pretty bad with alternate text encodings, I would suggest pure ASCII. 由于PHP通常对于备用文本编码来说非常糟糕,因此我建议使用纯ASCII。

Secondly, AES would be my preference for encryption, since there are solid, compatble implementations in PHP, JavaScript and .NET 其次,因为我在PHP,JavaScript和.NET中有可靠的兼容实现,所以我更喜欢AES加密

Have you looked at mcrypt ? 你看过mcrypt吗? Since it has many ciphers . 由于它有很多密码 Including MCRYPT_TRIPLEDES (libmcrypt > 2.4.x only) 包括MCRYPT_TRIPLEDES(仅libmcrypt> 2.4.x)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM