在 .NET 中实现强大且简单的加密技术?
我正在研究一个基于 .Net4 和 MVC3 的学生项目。 除了一些安全功能(例如用于保存在配置文件(例如连接字符串)中的编码/解码信息)之外,项目几乎已完成。
我想避免非常复杂的解决方案,因此我正在理想地在.NET中寻找一些易于使用的加密技术我只需提供 KEY 和字符串,它就会返回编码文本,反之亦然(类似于下面给出的 Base64 示例)。
我在线浏览了 MSDN 的 System.Security.Cryptography 命名空间文档,但它有我想对于像我这样的新手来说有很多选择。
请向我提供建议和实现这一目标的路径。 谢谢。
在搜索时,我发现了一个简单的 Base64 解决方案,我是这样实现的:
static public string EncodeTo64(string toEncode)
{
byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
string encodedValue = System.Convert.ToBase64String(toEncodeAsBytes);
return encodedValue;
}
static public string DecodeFrom64(string toDecode)
{
var toDecodeAsString = System.Convert.FromBase64String(toDecode);
string decodedValue = System.Text.ASCIIEncoding.ASCII.GetString(toDecodeAsString);
return decodedValue;
}
工作正常,但问题是据我所知,这不是非常可靠的东西,因为静态编码技术(没有自定义 KEY 的技术)可以轻松解码网上有很多在线 Base 64 解码器。我还尝试使用AES,如此处所述 但没能成功。
I am working over one my student project over .Net4 and MVC3.
Project is almost at completion except some security features such as Encoding/Decoding information for saving in config file such as Connection String etc.
I want to avoid a very complex solution and so I am looking for some easy to use Encryption technique in .NET ideally something where I can just provide a KEY and String and it gives me back the encoded text and vice versa (similar to the Base64 example given below).
I went through MSDN’s System.Security.Cryptography Namespace documentation online but it has a lot of options for a newbie like me I guess.
Kindly provide me with suggestions and path to follow to achieve it.
Thank you.
While searching I found a simple solution of Base64 which I implemented like this:
static public string EncodeTo64(string toEncode)
{
byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
string encodedValue = System.Convert.ToBase64String(toEncodeAsBytes);
return encodedValue;
}
static public string DecodeFrom64(string toDecode)
{
var toDecodeAsString = System.Convert.FromBase64String(toDecode);
string decodedValue = System.Text.ASCIIEncoding.ASCII.GetString(toDecodeAsString);
return decodedValue;
}
Works fine but the problem is as far as I’ve understood this is not something very reliable as a static encoding technique (one without a custom KEY) can be easily decoded and so many online base 64 decoders are available on net. I also tried to work with AES as expalined here but failed to succeed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了最大程度简单起见,只需查看 Windows 的数据保护 API (
您可以轻松地将其与
ProtectedData
类。
For maximum simplicity just have a look at Windows' Data Protection API (DAPI). This will provide encryption without requiring you to handle the keys.
You can easily use this with the
ProtectedData
class provided in .NET.这是一个简单的示例使用源代码进行简单字符串加密和解密< /强>
here is a simple example Simple String Encryption and Decryption with Source Code