简体   繁体   English

为假人在JS和C#之间共享加密的数据

[英]Sharing encrypted data between JS and C#, for dummies

My team must share data between a localnet html/js app, and a server in the same net listening on a websocket. 我的团队必须在localnet html / js应用程序和同一网络中的服务器上侦听websocket的共享数据。 The first idea was to simply send variables to the server with get 第一个想法是简单地使用get将变量发送到服务器

http://192.168.1.100:8080/var=hello

It's simple and works, but we must add a security level to the data exchange, encrypting all in Aes and then hexing the result to send it as plain string. 这很简单并且有效,但是我们必须在数据交换中添加安全级别,在Aes中全部加密,然后混合结果以纯字符串形式发送。

The best solution that we found is Crypto-JS https://code.google.com/p/crypto-js/ We are able to follow the examples and encrypting/decrypting data inside the same js block, but are unable to decrypt the data on another software. 我们找到的最好的解决方案是Crypto-JS https://code.google.com/p/crypto-js/我们能够按照示例并在同一js块内对数据进行加密/解密,但无法解密数据在另一个软件上。

we do: 我们的确是:

var text = "Message";
var password = "Secret Passphrase";

var encrypted = CryptoJS.AES.encrypt(text, password);

var EnText = encrypted.ciphertext; //returns the hexed/encrypted text
var Key = encrypted.key;

It doesn't work with the c# code running on the server, so we tried an online decrypting tool http://aes.online-domain-tools.com/ passing both the password and the Key, but similarly returns unreadable text 它不适用于服务器上运行的C#代码,因此我们尝试了一个在线解密工具http://aes.online-domain-tools.com/ ,同时传递了密码和密钥,但同样返回了无法读取的文本

JS generated value for reference JS生成值以供参考

EnText: 5768c9b4d75e0cc32b610d9e6f518c36
Key: 005e316192f5162f7fd104ce2c9fe91de6c6f2977849dcd5878226022a7073be

What are we missing? 我们缺少什么?

Ok i got it, the text is in hexadecimal. 好的,我明白了,文本为十六进制。 Try decyphering it there: 尝试在该处解密:

http://www.unit-conversion.info/texttools/hexadecimal/ http://www.unit-conversion.info/texttools/hexadecimal/

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

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