Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ProtectedData DataProtectionScope
Message
De
01/05/2007 12:00:22
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
01/05/2007 11:26:11
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Cryptographie
Divers
Thread ID:
01221511
Message ID:
01221531
Vues:
7
>I am using VS2005. I am trying to use the DPAPI through the ProtectedData Class to encypt passwords.
>
>However, when I try the below example, I always get errors on the ProtectedData and DataProtectionScope. The error messages are:
> The name 'ProtectedData' does not exist in the current context
> The name 'DataProtectionScope' does not exist in the current context
>
>What can I do to get this to work?
>
>
>using System.Security.Cryptography;
>
>class Program
>{
>static void Main(string[] args)
>{
>String plainText = "mypassword";
>String entropyText = "mykey";
>byte[] plainBytes = Encoding.Unicode.GetBytes(plainText);
>byte[] entropyBytes = Encoding.Unicode.GetBytes(entropyText);
>
>//Errors occur here.
>byte[] encryptedBytes = ProtectedData.Protect(plainBytes, entropyBytes, DataProtectionScope.CurrentUser);
>}
>}
>
>
>Thanks,
>
>Jerry

Jerry,
Are you sure it's not a casing issue? This worked pretty well for me:
using System;
using System.Text;
using System.Security.Cryptography;

class Program
{
static void Main(string[] args)
{
String plainText = "mypassword";
String entropyText = "mykey";
byte[] plainBytes = Encoding.Unicode.GetBytes(plainText);
byte[] entropyBytes = Encoding.Unicode.GetBytes(entropyText);

//Errors occur here.
byte[] encryptedBytes = ProtectedData.Protect(plainBytes, entropyBytes, DataProtectionScope.CurrentUser);
PrintValues(encryptedBytes);

byte[] decryptedBytes = ProtectedData.Unprotect(encryptedBytes, entropyBytes, DataProtectionScope.CurrentUser);

Console.WriteLine(Encoding.Unicode.GetString(decryptedBytes));


}

public static void PrintValues( Byte[] myArr )  
	{
	      foreach ( Byte i in myArr )  
		  	{
		         Console.Write( "\t{0}", i );
			 }
      Console.WriteLine();
	 }
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform