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

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

问题描述

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


$ b $ p

然后在客户端将通过Javascript代码进行解密。


$ b

$ b

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


$ b $注意:我可以完全在C#中执行,并通过Ajax进行解密,但是我不想这样做,因为我想尽可能地减少网站流量。

解决方案

System.Security.Cryptography 有一堆可以使用的对称(和非对称)加密算法。 (对于超级安全的使用,请 aes



您应该能够为大多数人找到匹配的Javascript实现(这里是JS中的一些实现)





注意:如果您打算使用基于私钥的加密,那么请记住,您的网页将嵌入其中的密钥,这意味着所有这些都是无意义的,因为任何访问该页面的人都可以进行解密,最多只会使屏幕刮板的使用更加困难。如果使屏幕刮刀更加生硬,那么您的目标就是使用obsfucation算法。任何琐碎的实现对于没有javascript引擎的屏幕刮板来说都是不切实际的:



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

然后onload使用这些函数的输出填充您的电子邮件字段。



Javascript加密对于为用户存储密码的软件具有非常好的用例ala clipperz


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.

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

Any thoughts on how to implement this?

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?

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.

解决方案

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

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

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:

Eg.

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

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

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

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

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