在.NET和Java脚本简单的字符串加密 [英] Simple string encryption in .NET and Javascript

查看:132
本文介绍了在.NET和Java脚本简单的字符串加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发中,我要加密的服务器上的短字符串ASP.NET MVC应用程序,使用C#,并将其发送给客户端。

I'm developing an ASP.NET MVC application in which I want to encrypt a short string on the server, using C#, and send it to the client-side.

然后在客户端就可以通过JavaScript code解密。

Then on the client-side it will be decrypted through Javascript code.

在如何实现这个有什么想法?

Any thoughts on how to implement this?

你知道一个简单的加密算法(并不一定是防弹保护),可以从C#很容易地转换为JavaScript或反之亦然?

Do you know of a simple encryption algorithm (doesn't have to be bullet-proof secure) that can be easily translated from C# to Javascript or vice-versa?

注:我能做到这一点完全用C#,并通过Ajax的做解密,但我preFER不要做这种方式,因为我想尽可能多的降低网站的流量尽可能

NOTE: I could do this entirely in C# and do the decryption through Ajax, but I'd prefer not to do it this way, as I want to reduce website traffic as much as possible.

推荐答案

的<一个href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx">System.Security.Cryptography有一堆的对称(和不对称)encrytion算法就可以使用。 (对于一些超安全使用 AES

The System.Security.Cryptography has a bunch of symetric (and asymetric) encrytion algorithms ready to use. (For something super secure use aes)

您应该能够找到匹配的Javascript实现大多数(这里有几个AES的实现在JS)

You should be able to find matching Javascript implementation for most (here are a few aes implementations in JS)

  • <一个href="http://www.movable-type.co.uk/scripts/aes.html">http://www.movable-type.co.uk/scripts/aes.html
  • <一个href="http://www.hanewin.net/encrypt/aes/aes.htm">http://www.hanewin.net/encrypt/aes/aes.htm
  • http://www.movable-type.co.uk/scripts/aes.html
  • http://www.hanewin.net/encrypt/aes/aes.htm

请注意:如果您计划使用私钥加密技术,然后记住,你的网页将有嵌入其中的关键,这意味着,这一切都变成一种毫无意义的原因任何访问该页面即可做解密,充其量你会使得画面刮刀一点点困难的生活。如果使画面撷取生活困难是你的目标,你可以只使用一个obsfucation算法。任何简单的实现会做出非常不切实际的没有一个JavaScript引擎,画面撷取:

Note: If you are planning to use private key based encryption then keep in mind, your web page is going to have the key embedded in it and that means that it all becomes kind of pointless cause anyone with access to the page can do the decryption, at best you would be making the life of the screen scrapers a little bit harder. If making screen scrapers life harder is your goal you could just use an obsfucation algorithm. Any trivial implementation would make very impractical for screen scrapers that do not have a javascript engine:

例如。

function samObsfucated()
{
    return("s" + "a" + "m" + "@" + "s" + "." + "com");
}

然后onload事件填充您的电子邮件领域具有这些功能的输出。

Then onload populate your email fields with the output of these functions.

Java脚本加密有一个很好的使用案例,软件,存储用户密码阿拉 clipperz

Javascript encryption has a really good use case for software that stores passwords for users ala clipperz

这篇关于在.NET和Java脚本简单的字符串加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆