c#中的数据加密 [英] encryption of the data in c#

查看:77
本文介绍了c#中的数据加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜!伙计们,我刚刚在Google上看到这段代码



hi! guys i just came through this code on Google

public string Encrypt(string plainText)
   {
       if (plainText == null) throw new ArgumentNullException("plainText");

       //encrypt data
       var data = Encoding.Unicode.GetBytes(plainText);
       byte[] encrypted = ProtectedData.Protect(data, null, Scope);

       //return as base64 string
       return Convert.ToBase64String(encrypted);
   }



并试图实现它,因为我在理解代码时遇到了一些困难。但问题是我无法运行检查它是如何工作的,因为当我尝试运行时我得到2个错误,如下所示:



当前上下文中不存在名称'ProtectedData' />


当前背景下不存在范围这个名称



idont知道该做什么



有些人可以帮我解决这个问题



i意味着我应该做些什么来使上面的代码工作或者有人可以帮助我解释整个程序的工作和它使用的librires



这里是我使用的系统命名空间


and tried to implement it since i had some difficulty in understanding the code .But the problem is i'm unable to run and check how it works because when i try to run i get the 2 errors they are as below:

The name 'ProtectedData' does not exist in the current context

The name 'Scope' does not exist in the current context

idont know what to do

can some body help me out in this

i mean what should i do to make the above piece of code work or can somebody help me out iby explaining the whole program with its working and librires it uses

here are the system namespaces which i used

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;





提前谢谢。



thank you in advance.

推荐答案

例如

检查这个线程



这篇CP文章

简单加密和解密C#中的数据 [ ^ ]

http://msdn.microsoft.com/ en-us / library / system.security.cryptography.aspx [ ^ ]
For Example
Check this Thread
and
this CP Article
Simple encrypting and decrypting data in C#[^]
http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx[^]


嗨伙计们只是添加对我的项目的引用它我的参考是system.security

然后必须将范围字段更改为DataProtectionScope.LocalMachine

添加的步骤参考如下:

转到您的项目节点并右键单击 - >添加参考 - > .net(标签名称) - > system.security
hi guys it was just to add a reference to my project it the reference that i had is system.security
then had to change the scope field to DataProtectionScope.LocalMachine
the steps to add reference are below:
go to your project node and right click -> add reference-> .net(name of the tab) -> system.security


看起来你没有复制完整的代码。

如果你看一行 ProtectedData.Protect(数据) ,null,Scope); ,您尚未定义两个值, ProtectedData 范围程序内的任何地方。需要为这些复制的代码定义这些(以及它们的类型)。
It looks like you have not copied the complete code.
If you look at the line ProtectedData.Protect(data, null, Scope);, you have not defined two values, ProtectedData and Scope anywhere within the program. These (along with their types) need to be defined for this copied code to work.


这篇关于c#中的数据加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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