Creating and Retrieving a Profile Instance with an Encrypted Property

Encryption-enabled Web sites must contain code that creates new profiles with encrypted properties as well as code that retrieves the encrypted properties from the database, decrypts, and displays them. The following code sample illustrates this functionality; it also illustrates retrieving the encrypted values from the database to contrast this functionality with retrieving decrypted values. In this example, assume that the encryption of the profile property SSN uses asymmetric encryption.

Ee825410.note(en-US,CS.20).gifNotes

  • Profile names that are longer than 57 characters long cannot be exported to the Data Warehouse.
  • Setting values on encrypted properties is the same as setting values on non-encrypted properties; once the connection string has been provided, calls to assign values to variables always use the same syntax, independent of whether or not the value is to be encrypted.
  • The keyIndex field is read-only
option explicit 
Dim ProfileSvc 
Dim ProfileObject
Dim GenInfo
Dim dsn
Dim PublicKey, PrivateKey1, PublicKey2, PrivateKey2 
PublicKey = "<hex-string>" 
 
' Build Connection String
PrivateKey1 = "<hex-string>" 
dsn = "Provider=CSOLEDB;Data Source=<server>;Initial Catalog=Retail_commerce;User ID=<user-id>;Password=<password>;"
Dsn = Dsn & "PublicKey=" & PublicKey & ";PrivateKey1=" & PrivateKey1 & ";KeyIndex=1"

' Initialize Profile Service
Set ProfileSvc  = CreateObject("Commerce.ProfileService") 
Call ProfileSvc.Initialize (dsn, "Profile Definitions") 

' Get Profile
Set ProfileObject = ProfileSvc.CreateProfile("jackcool7@somewhere.com","UserObject") 

' Set Properties
Set GenInfo=ProfileObject.Fields.Item("GeneralInfo") 
GenInfo.Value.Item("first_name").Value="Jack"
GenInfo.Value.Item("last_name").Value="Cool7"
GenInfo.Value.Item("user_title").Value="Mr."
GenInfo.Value.Item("SSN").Value="123-45-6789" 

' Writing to keyIndex will fail, keyIndex is read-only
'GenInfo.Value.Item(<keyIndex).Value=2

ProfileObject.Update 

' Read Properties
MsgBox GenInfo.Value.Item("SSN").Value 
MsgBox GenInfo.Value.Item(<keyIndex>.Value

' Cleanup
Set ProfileObject=nothing
Set ProfileSvc=nothing 
MsgBox "Done!"

Copyright © 2005 Microsoft Corporation.
All rights reserved.