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)
{
}
}
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)
{
}
}