Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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);
   }

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.
Posted
Updated 13-Apr-12 20:22pm
v2
Comments
Abhinav S 14-Apr-12 2:22am    
Code tags added.

 
Share this answer
 
Comments
Abhinav S 14-Apr-12 2:57am    
This might help the OP. 5.
uspatel 14-Apr-12 2:58am    
Thanks Abhinav........
shrav007 14-Apr-12 3:04am    
thank you for the links it was really useful
uspatel 14-Apr-12 3:10am    
You're most welcome.
You can accept this solution if it really helps.
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
 
Share this answer
 
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.
 
Share this answer
 
Comments
shrav007 14-Apr-12 2:27am    
actually only this part was given there let me give you the link of the site where i found this code http://stackoverflow.com/questions/1678555/password-encryption-decryption-code-in-net
Abhinav S 14-Apr-12 3:00am    
Have a look at the ProtectedData class. It should give you an idea of what to do next.
shrav007 14-Apr-12 3:06am    
thank you for the advice

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900