Get 'Password' from byte[] of connection properties using ArcObject

2210
1
10-21-2013 08:45 PM
VinayakJogade
New Contributor
Hi,

I am calling stored procedure from oracle, explicitly, for which I require connection information of existing workspace file.
After searching on the forum, got information about collecting connetion properties using IPropertySet interface.
I can get all the connection properties through it, however 'password' field is in the form of byte[] and I think which is encrypted.
Anybody knows, how to retrieve 'Password' from byte[] of connection properties ?
0 Kudos
1 Reply
FreddieGibson
Occasional Contributor III
It wouldn't be possible to get decode the password using any esri/ArcObjects functionalities.  The password word is designed to be encrypted for security reasons.  What you could try instead is to just pass the byte[] object to your new PropertySet class.  I tried this on my machine and it appears to work.  The code I used is as follows:


public static void GetConnPropsSdeFile(string sdeFile)
{
    Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
    IWorkspaceFactory pWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
    IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(sdeFile, 0);

    object names, values;
    IPropertySet pPropSet = pWorkspace.ConnectionProperties;
    pPropSet.GetAllProperties(out names, out values);

    DisplayConnectionProperties(pPropSet, names);
}


public static void DisplayConnectionProperties(IPropertySet pPropSet, object properties)
{
    string value = "";
    string[] sNames = properties as string[];

    string[] baseProps =
    {
        "SERVER", "INSTANCE", "DBCLIENT", "DB_CONNECTION_PROPERTIES", "DATABASE",
        "AUTHENTICATION_MODE", "USER", "PASSWORD"
    };

    IPropertySet pPropertySet = new PropertySetClass();

    for (int i = 0; i < pPropSet.Count - 1; i++)
    {
        value += sNames.ToUpper() + ": " + pPropSet.GetProperty(sNames) + "\n";
               
        string key = sNames.ToUpper();
        if (baseProps.Contains(key))
            pPropertySet.SetProperty(key, pPropSet.GetProperty(key));

    }

    Console.WriteLine(value);

    Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
    IWorkspaceFactory pWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
    IWorkspace pWorkspace = pWorkspaceFactory.Open(pPropertySet, 0);
    Console.WriteLine(pWorkspace.Exists());
}