Impersonate registry user/pwd

O

ogled

Hi
I have a little problem...I have an app where I'd like to set the user/
pwd for the impersonate that my IIS should use. Textwise this works
fine, i encrypt and decrypt and get the right values, but when I try
to use it in the aspnet project it won't start.

To save it in the registry I have according to the documentation saved
the values as regbinary and used the cryptprotectdata (the DPAPI
class)

to convert the data to bytearray[] before I save the values I do
public static byte[]
StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=new
System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
public static string ByteArrayToStr(byte[] str)
{
System.Text.ASCIIEncoding encoding=new
System.Text.ASCIIEncoding();
return encoding.GetString(str);
}

Can this be the problem that IIS-cannot load credentials?

Oh..and I encode like this:


RegistryKey typeKey = Registry.LocalMachine.OpenSubKey("Software\\XXX\
\XXX\\Server\\XXXXX");
System.Security.Permissions.RegistryPermission regPermission = new
System.Security.Permissions.RegistryPermission(System.Security.Permissions.PermissionState.Unrestricted);
regPermission.AddPathList(System.Security.Permissions.RegistryPermissionAccess.Write,
"HKEY_LOCAL_MACHINE\\SOFTWARE\\XXX\\Server\\XXX");

string entropy = null;
if (UID.Length > 0 && PWD.Length > 0)
{
if(!blnCrypt)
{
try
{
kreg.SetValue("SOSUSR",
StrToByteArray(DPAPI.Encrypt(DPAPI.KeyType.MachineKey, UID)));
kreg.SetValue("SOSPWD",
StrToByteArray( DPAPI.Encrypt(DPAPI.KeyType.MachineKey, PWD)));
}
catch(Exception Ex)
{

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top