J Beaulieu - CS Product Team

I have a situation in which I'm creating the ProfileContext object directly, and passing in the database connection string.

According to the ProfileContext constructor documentation, I can pass a hexadecimal representation for the private and public encryption keys, as well as the key index. This should allow for manipulation of the encrypted fields.

I have generated the keys, and they have been added to the registry. I then add the keys to the connection string in a format like this:

Provider=CSOLEDB;Data Source=mymachine;Initial Catalog=MySite_profiles;Integrated Security=SSPI;PublicKey=0001;PrivateKey=0001;KeyIndex=1

For the sake of being brief, I have truncated the Key values from above. I am reading the binary values from the registry, and concatenating each value in the format of XX, so 1 being represented as 01.

The exception being thrown during construction of ProfileContext is:
"Object reference not set to an instance of an object."

Any ideas

-jb


Re: Commerce Server 2007 Accessing/setting encrypted profile data

jeffbone

More information - the inner exception has the following:
"Failed to import PublicKey"

-jb




Re: Commerce Server 2007 Accessing/setting encrypted profile data

Max Akbar

I would go the App.config way. Just add the same values from the web.config into the app.config and you should be fine.

-Max






Re: Commerce Server 2007 Accessing/setting encrypted profile data

jeffbone

Actually, I did have that in my app.config, just failed to mention it :-)

Is there perhaps something else I'm missing
Thanks Max.

-jb




Re: Commerce Server 2007 Accessing/setting encrypted profile data

Max Akbar

This code works for me:

Code Snippet

string profileServiceConnectionString = "Provider=CSOLEDB;Data Source=CS2007RTM;Initial Catalog=StarterSite_profiles;Integrated Security=SSPI;PublicKey=06020[truncated];KeyIndex=1;PrivateKey1=070200[truncated];";

ProfileContext pctx = new ProfileContext(profileServiceConnectionString, new ConsoleDebugContext(DebugMode.Debug));

Profile profile = pctx.GetProfile("{a75a3c9c-5424-4a6b-983c-d680d50c8043}", "CreditCard");

Looking at what you have I think you named the private key wrong it should be PrivateKey1="XXXX"

Good luck,

-Max







Re: Commerce Server 2007 Accessing/setting encrypted profile data

jeffbone

How right you are. I'm still receiving the same error however.
"Failed to import PublicKey".

Anything else that I could be missing

-jb




Re: Commerce Server 2007 Accessing/setting encrypted profile data

Max Akbar

Then your encryption keys are not valid. Can you post the entire connection string

-Max






Re: Commerce Server 2007 Accessing/setting encrypted profile data

jeffbone

Sorry for the delay - was sidetracked. My connection string is below.

I'm reading the keys from the registry as an array of bytes:

Code Snippet
byte[] byteArray = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Commerce Server 2007 Keys\StarterSite", "PublicKey", null) as byte[];

byte[] byteArray2 = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Commerce Server 2007 Keys\StarterSite", "PrivateKey", null) as byte[];

I then loop through the array, formatting each value as a hex string.

"Provider=CSOLEDB;Data Source=machine1425-59;Initial Catalog=StarterSite_profiles;Integrated Security=SSPI;Connection_Retry=1;Connection_Retry_Delay=5;PublicKey=01000000D08C9DDF0115D1118C7A00C04FC297EB01000000AC4EC70E8789DD4A9A238C53EAA6462B0400000002000000000003660000A8000000100000004BB3F80D63C12D430180CA822ABAA3A60000000004800000A000000010000000CFDB806BEA8C016EDE71EEE4B9A1173E3001000048B5ED0CD116FB9BD72A4CD828A45CA9D118BD17F525211478552053124C4A9AEAAD272025855A2AC6B9009CFD8B417CB2C8DF0084682D293FC15F20C9B871061A064507DED2D5906078D46C524BEFB7761FDC605F4D0C621623A69E523A9D67BE5A3CFC9DA4D2E4B6FA280F748BA4DC32C5047DA8BEB4CB56939159C514E31752385F6757DC1435AEEA06C6672A37097A422C82583F9B08C69E1747F79E2A7CB037550FC4301C831B7C9EA6A814F0E17EE16AC6003AD6E11BF69B0ACABCB2890B7FE1AB0CDBA2380C307023D427F7C209BE69FDAC8FE10973A59EA2C2CDB255BB37FDC2F0DD4D449BC19AD8CE30D9BBB6E42BB226CDFF68638372369B8406B5865B6D68F73C4CC69B33A6C206116BDA1373D707913407703A5823BC3823BEBA79DC311914C0EE44BC1E5165D516B5341400000006CD0A16E687480D20261F9A5B06E48801B10200;PrivateKey1=01000000D08C9DDF0115D1118C7A00C04FC297EB01000000AC4EC70E8789DD4A9A238C53EAA6462B0400000002000000000003660000A800000010000000262F04E3CF6E9185F7F7E369E6204BEB0000000004800000A000000010000000B70D80CE7D0ADB1F58956785278B4689B0040000EB7B1903CA1E59C96ED1AF6E0AC2647D2AD2526317CD447C5CF1FD63C43794FFDC842817E6DA01F0EE6CB629F1D2EBBB699AFFEB1E728A2796829EB901216FD9B2A5F27EFEC28FDF4E285CCB48803A334A57E62C231F7C4AD69935038323A86AE1932FA117AA6372F4BE20CAAC7D274504855D3CF7CBC946C1EAB6D60EF5EED032C35535DC434171B412F0BED74E59A45ECB2EE5579F30F46725FC9939873A94D14229BB4C8EFA44FDDAED8B31D45D02570188BDB604C8A3CA02471633E0F58CFFA620DE3FC8E425203CD48ABA007F3F15232B0FC52D9285E295B7AC0682680C05BAA39567C455D3DF6223CE0979512249D7C6463596D91BB69BA45C194C0F345D33B22F381E0855CD2C0C4529F72B2F103E3017D7A1C61FBF9FEBB9A8EE75CA9F871BF9D2329075D3FFF65AE53BBBD641CE6F28CBB6247AAC304FAD4E9E9B02A04EC6CD2F45B166BA723CC45AE64841525F33DBD712E7A7042F353FDFB032D87A85BF84EBF6FBE93277CCC480E982CF528793AD856CC3F05F81EBF8FF6F4D666E8F3ABC128C8704626B65E9EB7B23D94F3870A5297E66580A0CC59579FFAEA3F4C79DC64609EE92E8D9C49E51427E3A5B0698224D5C4401E90D1387852EC2EF5D630895431B3E2AAA8A0BD7106B86C8A68C3D91E353B4C2B4C7C5595C266CE82043A14F78A1D322BEA250668ADE5A15E936A882FBBA67F80EF9B9AD7ACF566DFECF1E8B18F3C58FD5A30D29139C8D44C9E49E762F706EB91D6385FB37B55DD4672945983EE30A0361056C92387F8D25EFA72450F2C1233B48A8578CE07053979D9AFB1977DAA544A583352D29BDC41A1D8389B7EEACF770D6A5D2577EA38F7439123F5FC302A7839393CDEF809853088856A01EBD196236CFE53275ECEFAFA0FB4B5F328AE8D4406DF8B12E95A5B126FB1E558DC948D3C88BBF1A58EAE975875DE293FFBF5342B8344BC708610890E978AE0B5758246FD253C92D9E803CD194A23FD7EF251FD8E6A5F6B74A9FBBD8C89B857EB0D4EC0830120962B4966F7802E8CC778E043E2FAAC05BC1B70B4E4BBAEBC0E85A0CD80C8CE8B1C54B6B748F466D0D9CB4B88FA491ABA81414E774C56DD9289FBE0DBDA37DD8CCE227D1BF22D2440FF35C7E50EC0BB83514F5180F4F3A15C31B54E40B4F53723DAF842F23C2AB720F644A6EDD3162451E26E32362EBB26AB6A612949DA09F1DA139A3F1B43F0E795E296AC0ED277595752D3F0E7B7C4E5A07A4F4BA30F49B88A144E0D46702F2535235F6E4ECB8BBAA455C6F9FECDA52B4FC6534DFFCC982EC1D6C166068DBE233D851E974A9C39A928BB70AF2B53EAE780B4E96707FE4B5E15E8EEE8B193973B263481B79CC68742DF2E2321077BE8C98CD2B25A86BA3E758703CA9A8AEAA07CAC628E6DA8FCA93C39C66870A49D77B9F5A0870AC1AC02D7F9082C9E6826B49ABC1D70A3058FDE885B3011E5177EF786597243BE06B7C2342DB8EA9B7D2EF4AF44E5A3B3DC1C3474D2BDE4C31FC67597D10E88687696F4D045D514C6FF2C8C23799840908AD2B2895F80D3ACE483C90E6B3BB04EFCB461467FEEC21F58FEA9A7EAF5EDD0C5F91BF9AD1C1F3A0F916B47073DAE60FB08E0299C0A59E06B38B89CE2E208BF4F14E53752FEDC8DAFF61AF36EF4C99C7FB7ED206E46F146AE49AF87245F32272FFB759DA975155C17B995B1400000044E6E78219584BCC860DCDD73FBF57CB582A3755;KeyIndex=1"

Thanks.

-jb




Re: Commerce Server 2007 Accessing/setting encrypted profile data

Max Akbar

Just as a test can you just open the registry and cut and past the key values to the connection string and see if it can connect That's how I did my test and it works just fine. Also can you read the profile values from the web site and having the reg keys in the web.config

-Max