简体   繁体   English

PHP和JS中可逆加密的单一机制

[英]Single mechanism for reversible encryption in PHP and JS

The problem arose to encrypt data transmitted between client and server using a key without using https (the key is transmitted separately, that's another story.) So. 出现了使用密钥而不使用https加密在客户端和服务器之间传输的数据的问题(密钥是单独传输的,这是另一回事了。) Are interested in the mechanism. 对机制感兴趣。 I know that there is no built-in JS encryption functions, and PHP are many, but not all normal decode UTF8. 我知道没有内置的JS加密功能,PHP有很多,但不是所有的正常解码UTF8。

Question: Is there a ready-made solutions (if possible with examples) of such a problem? 问题:是否存在此类问题的现成解决方案(如果可能,还提供示例)?

I've solved this problem with pidCrypt which has a working RSA implementation in JavaScript. 我已使用pidCrypt解决了此问题,该工具在JavaScript中具有有效的RSA实现。 There is also jCryption which I've never used. 还有我从未使用过的jCryption

I recently had to implement this in virtually the only case where it's valid to do so: We were storing data offline in the application cache, and a non-negotiable business requirement stated that it be encrypted while there. 最近,我不得不在几乎唯一有效的情况下实施此操作:我们将数据脱机存储在应用程序缓存中,并且有一个不可商议的业务要求,要求在此位置对其进行加密。 Unless you're doing something similar, the answer is to use SSL and throw out any hope of implementing a JS solution to this problem. 除非您执行类似的操作,否则答案是使用SSL并放弃实现此问题的JS解决方案的希望。 You need SSL to securely transmit the code to the browser, or any encryption you do there is fundamentally insecure. 需要 SSL才能将代码安全地传输到浏览器,否则您在其中进行的任何加密从根本上都是不安全的。

Overall I found the solution to my problem. 总的来说,我找到了解决问题的方法。 I used the algorithm AES CBC 256 bit. 我使用了AES CBC 256位算法。 Library Gibberish AES (https://github.com/mdp/gibberish-aes) and fork on php (https://github.com/ivantcholakov/gibberish-aes-php/blob/master/GibberishAES.php) 库Gibberish AES(https://github.com/mdp/gibberish-aes)并在php上进行分叉(https://github.com/ivantcholakov/gibberish-aes-php/blob/master/GibberishAES.php)

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

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