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

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

问题描述

我正在开发一个 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代码解密.

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 进行解密,但我不想这样做,因为我想尽可能减少网站流量.

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.

推荐答案

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

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

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

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

注意:如果您打算使用基于私钥的加密,那么请记住,您的网页将嵌入密钥,这意味着这一切都变得毫无意义,因为任何有权访问该页面的人都可以进行解密,充其量会使屏幕刮刀的寿命变得更难一些.如果您的目标是让屏幕抓取器的生活更难,那么您可以使用混淆算法.对于没有 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.

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

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

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

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