hi! guys i just came through this code on Google
//encryption
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
//namespace
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;

sorry there is some mistake that the question part and code part have mixed upbut i guess u can still understand what it is if not here is the code part:

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);
}

guys i figured out the problem it was just to add an reference System.Security and then change the scope value to DataProtectionScope.LocalMachine you can find the reference at .net
that is right click on references in your project and then add reference then in the tab .net you'll find the above reference

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.