Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6117579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:20:13+00:00 2026-05-23T15:20:13+00:00

Im creating an application, wich will conect to several sql database and get some

  • 0

Im creating an application, wich will conect to several sql database and get some details form the database,

In this application i have to encrypt the database connection details such as user name passwords. yes its pritty straight forward and simple just write a metod to decrypt the credentials.

but in my case i have to rely on third party encription mechanisam to decrypt the credentials. more over i have to connect to several sql servers which will again used some other encryption methods. hence im cording my application to load a encryption assembly dynamically and call the encryption method.

but when i load the assembly form Assembly.LoadFile(“Path”) i cannot unload the loaded assembly. i think i have load this assembly in separate app domain and call the relavant methods and unload that appdomain. im needing some help on this part. due to my lack of knoladge i cannot call the required method. my code as follows. please help me on this.

class ApplicationSettings
{

    private static ApplicationSettings m_ApplicationSettings;
    public String m_ServerName { get; private set; }
    public String m_DatabaseName { get; private set; }
    public String m_UserID { get; private set; }
    public String m_Password { get; private set; }
    public String m_EncryptionDLLPath{ get; private set; }
    public String m_NameSpace { get; private set; }
    public String m_ClassName { get; private set; }
    public String m_EncryptionMethodName { get; private set; }
    public String m_DecryptionMethodName { get; private set; }

    private ApplicationSettings()
    {
        m_ApplicationSettings = this;
    }

    public static ApplicationSettings CurrentValues
    {
        get
        {                
            return m_ApplicationSettings;
        }
        private set
        {
            m_ApplicationSettings = value;
        }
    }

    internal static void Initialize()
    {
        CommonFunctions.DataEncryption _enc = new CommonFunctions.DataEncryption();


        ApplicationSettings.CurrentValues = new ApplicationSettings();
        ApplicationSettings.CurrentValues.m_EncryptionDLLPath = @"C:\Users\Administrator\Documents\Visual Studio 2010\Projects\TestApp\TestApp\bin\Debug\AppSec.dll";
        ApplicationSettings.CurrentValues.m_NameSpace = "AppSec";
        ApplicationSettings.CurrentValues.m_ClassName = "AppSecEncDec";
        ApplicationSettings.CurrentValues.m_EncryptionMethodName = "Encrypt";
        ApplicationSettings.CurrentValues.m_DecryptionMethodName = "Decrypt";
        ApplicationSettings.CurrentValues.m_Password = _enc.Decrypt("pzBS3EJDoGM=");
        ApplicationSettings.CurrentValues.m_UserID = "sa";

    }



}

class DataEncryption
{

    AppDomain DomainName;        

    //Call the Encryption Method 
    public String Encrypt(Object _DataToEncrypt)
    {


    }

    //Call the Decryption Method 
    public String Decrypt(Object _DataToDecrypt)
    {
        String _Decrypt = "";

        String assemblyFileName = ApplicationSettings.CurrentValues.m_EncryptionDLLPath;
        String assemblyName = ApplicationSettings.CurrentValues.m_NameSpace;

        //Setup the evidence
        Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
        AppDomain TestDomain = AppDomain.CreateDomain(
          "TestDomain", //The friendly name of the domain.
          evidence,   //Evidence mapped through the security policy to establish a top-of-stack permission set.
          AppDomain.CurrentDomain.BaseDirectory,  // The base directory that the assembly resolver uses to probe for assemblies.
          System.IO.Path.GetFullPath(assemblyFileName),    // The path relative to the base directory where the assembly resolver should probe for private assemblies.
          true  // If true, a shadow copy of an assembly is loaded into this application domain.
          );
        string s = TestDomain.Load(assemblyName).FullName;
        string[] myparam = new String[1];
        myparam[0] = "test";


        TestDomain.CreateInstance(TestDomain.Load(assemblyName).GetName().ToString(), ApplicationSettings.CurrentValues.m_NameSpace + "." + ApplicationSettings.CurrentValues.m_ClassName).CreateObjRef(GetType());
        //her i need to execute the Encrypt method which will load form the third party encryption mechanisam

        //method name will be returnd on this parameter in application settings Classes.ApplicationSettings.CurrentValues.m_EncryptionMethodName ;

        UloadAssembly();

        return _Decrypt;
    }


    public void UloadAssembly()
    {
        //Unload the loaded appdomain
        AppDomain.Unload(DomainName);            
        GC.Collect();
    }


}

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:20:13+00:00Added an answer on May 23, 2026 at 3:20 pm

    I have figured out how to do this and hope fully it will be successful please find the below code which if used to over come the situation

           public String Encrypt(Object _DataToEncrypt)
        {
            try
            {
    
                String _Encrypt = "";
                LoadAssembly();
                ShowLoadedAssemblies();
                if (ClassInstance != null)
                {
                    MethodInfo EncryptionMethod = ClassInstance.GetType().GetMethod(Classes.ApplicationSettings.CurrentValues.m_EncryptionMethodName); ;
                    if (EncryptionMethod != null)
                    {
                        object[] myparam = new object[1];
                        myparam[0] = _DataToEncrypt;
                        _Encrypt = (string)EncryptionMethod.Invoke(null, myparam);
                    }
    
                }
    
                UloadAssembly();
                ShowLoadedAssemblies();
                return _Encrypt;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
    
    
            }
    
        }
    
        //Call the Decryption Method 
        public String Decrypt(Object _DataToDecrypt)
        {
            String _Decrypt = "";
    
            LoadAssembly();
            ShowLoadedAssemblies();
            if (ClassInstance != null)
            {
                MethodInfo DecryptionMethod = ClassInstance.GetType().GetMethod(Classes.ApplicationSettings.CurrentValues.m_DecryptionMethodName);;
                if (DecryptionMethod != null)
                {
                    object[] myparam = new object[1];
                    myparam[0] = _DataToDecrypt;
                    _Decrypt = (string)DecryptionMethod.Invoke(null, myparam);
                }               
    
            }
            UloadAssembly();
            ShowLoadedAssemblies();
            return _Decrypt;
        }
        //Loading the Assembly 
        public void LoadAssembly()
        {
    
    
    
    
            Evidence evi = new Evidence(AppDomain.CurrentDomain.Evidence);
    
            DomainName = AppDomain.CreateDomain(Classes.ApplicationSettings.CurrentValues.m_NameSpace
                                                , evi
                                                , AppDomain.CurrentDomain.BaseDirectory
                                                , Classes.ApplicationSettings.CurrentValues.m_EncryptionDLLPath
                                                , true
                                                );
    
           String LoadingAssemblyName = AssemblyName.GetAssemblyName(Classes.ApplicationSettings.CurrentValues.m_EncryptionDLLPath).FullName;
    
           ClassInstance = DomainName.CreateInstanceAndUnwrap(LoadingAssemblyName
                                                               , Classes.ApplicationSettings.CurrentValues.m_NameSpace 
                                                                  + "." 
                                                                  + Classes.ApplicationSettings.CurrentValues.m_ClassName
                                                               );
    
        }
        public void UloadAssembly()
        {
            //Unload the loaded appdomain
            AppDomain.Unload(DomainName);            
            GC.Collect();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating some application that plays sounds like piano, drums etc. I have a
I'm creating an application that needs to run under multiple databases. I currently have
I am creating an application that the user will be able to setup a
I have a singleton that I use for creating an application wide report. As
I am creating application in AIR using JavaScript. Many of my functions requires text
I am creating an application where i am downloading a large file from dropbox
I am creating an application using Grails Framework for which I plan to use
I'm creating an application in C# using Visual Studio 2010/.NET 4.0. For part of
i am creating an application in which i want set different background images in
I'm creating an application (using PHP / Codeigniter / MYSQL) for tracking volunteers at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.