Impersonate registry user/pwd

Discussion in 'ASP .Net Security' started by ogled, Feb 25, 2008.

  1. ogled

    ogled Guest

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

    }
    }
    ogled, Feb 25, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HK
    Replies:
    1
    Views:
    3,605
    Cowboy \(Gregory A. Beamer\)
    Apr 1, 2004
  2. Bill Belliveau

    DirectoryEntry Impersonate or WindowsIdentity Impersonate?

    Bill Belliveau, Jan 28, 2004, in forum: ASP .Net Security
    Replies:
    3
    Views:
    328
    Joe Kaplan \(MVP - ADSI\)
    Jan 31, 2004
  3. Thauhtopa
    Replies:
    4
    Views:
    281
    Thauhtopa
    Dec 7, 2004
  4. Maria
    Replies:
    0
    Views:
    94
    Maria
    Apr 13, 2005
  5. Lasse Edsvik

    specify user+pwd in CDO/CDONTS

    Lasse Edsvik, Dec 12, 2003, in forum: ASP General
    Replies:
    11
    Views:
    223
    Aaron Bertrand - MVP
    Dec 15, 2003
Loading...

Share This Page