Freigeben über


Decrypting Profile Data

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

After encrypting your profile data, you need to verify encryption and retrieve the decrypted property values.

To verify encryption and retrieve decrypted property values

  1. Use the Profile Key Manager utility to generate a private key and a public key.

  2. Create a ProfileContext object by passing it a connection string.

  3. Get the user's profile by calling the GetProfile method of the ProfileContext object.

  4. Iterate through all the ProfilePropertyGroup objects in the ProfilePropertyGroupCollection collection.

Example

The following code example shows how to decrypt profile data.

using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Runtime;
using Runtime = Microsoft.CommerceServer.Runtime.Profiles;
using RTDbg = Microsoft.CommerceServer.Runtime.Diagnostics;

// tbLogin - TextBox with profile's logon name, for example, "JoeUser"
// tbPropGroup - TextBox with property group name, for example, "AccountInfo"
// tbPropName - TextBox with property name, for example, "SSN"

try
{
    // publicKey and privateKey values generated by ProfileKeyManager.exe.
    string publicKey = "<publicKey>";
    string privateKey = "<privateKey>";

    // Profile Connection String - value can be retrieved from Commerce Server.
    // Manager, Console Root -> Commerce Server Manager -> Global Resources -> 
    // Profiles, right-click and select Properties, highlight 
    // s_ProfileServiceConnectionString.
    string connString = "Provider=CSOLEDB;Data Source=<computername>;Initial Catalog=<CS Site>_commerce;Integrated Security=SSPI;";

    // To decrypt, specify PrivateKey1= and KeyIndex1= if you encrypted 
    // using /i 1 with ProfileKeyManager, or PrivateKey2= and KeyIndex2= if you specified 
    // /i 2 with ProfileKeyManager. 
    if (cbDecrypt.Checked)
    connString += "PublicKey=" + publicKey + ";PrivateKey2=" + privateKey + ";" + "KeyIndex=2";

    RTDbg.ConsoleDebugContext debugContext = new 
    RTDbg.ConsoleDebugContext(RTDbg.DebugMode.Debug);
    Runtime.ProfileContext rtCtxt = new Runtime.ProfileContext(connString, debugContext);

    Runtime.Profile p = rtCtxt.GetProfile(tbLogin.Text.Trim(), "UserObject");
    foreach (Runtime.ProfilePropertyGroup ppg in p.PropertyGroups)
    {
        if (ppg.Name == tbPropGroup.Text.Trim())
        {
            foreach (Runtime.ProfileProperty pp in ppg.Properties)
            {
                if (pp.Name == tbPropName.Text.Trim())
                    Console.WriteLine(pp.Name + " = \"" + pp.Value.ToString() + "\"", " Property Value");
            }
        }
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

See Also

Other Resources

How to Add Encrypted Properties for Profiles

Profiles System Tools

Profile Key Manager

Preparing to Use the Profile Key Manager

Generating a New Encryption Key

Denying Updates

Updating the Application Runtime

Updating the Stored Data

Using the Profile Key Manager

Profile Key Manager Command Line Utility Reference