We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

vasu0020
Posts: 22
Joined: Wed Aug 27, 2014 9:55 am

Return value from c# custom action to Property

Hi Team,
My requirement is to encrypt a user provided value(db connection password) and update the encrypted value in a connection string in web.config(XML) file. I want to use another dll to encrypt the password.
As suggested in http://www.advancedinstaller.com/user-g ... rp-ca.html link, I am able to encrypt the password.
I want to return the encrypted value in the dll i.e. currently in session.Item("RET_VAL_FROM_ENCRYPT").
Below is the code snippet to encrypt the password.
[CustomAction()]
public static ActionResult CA_EncryptString(Session session)
{
session.Log("Begin CA_EncryptString");
string sToEncrypt = "";
try {
sToEncrypt = session.Item("VAL_TO_ENCRYPT");
session.Item("RET_VAL_FROM_ENCRYPT") = EncryptDecrypt.EncryptDecrypt.Encrypt(sToEncrypt);
MessageBox.Show(session.Item("RET_VAL_FROM_ENCRYPT")); // This is showing the encrypted password
} catch (Exception ex) {
session.Log("Error in CA_EncryptString: " + ex.Message);
return ActionResult.Failure;
}
session.Log("End CA_EncryptString");
return ActionResult.Success;
}
Kindly suggest the way to return value in session variable to custom action and then update the value in web.config file.

Thanks in advance
Srinu Gatla
vasu0020
Posts: 22
Joined: Wed Aug 27, 2014 9:55 am

Re: Return value from c# custom action to Property

I have created custom actions, and able to send input password and encrypt it.
We are struck while returning the encrypted value. refer from below post code to return the value.

session.Item("RET_VAL_FROM_ENCRYPT")

i want to use the value in this "RET_VAL_FROM_ENCRYPT" variable in advanced installer.

Can any one please help us on this?

Thanks in advance
Srinu
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Return value from c# custom action to Property

Hello Srinu,

Please keep in mind that in order to get an installer property (i.e. VAL_TO_ENCRYPT) within your C# custom action you should use a statement like this:

Code: Select all

sToEncrypt = session["VAL_TO_ENCRYPT"];
Also, in order to set an installer porperty (i.e. RET_VAL_FROM_ENCRYPT) you should use a statement like this:

Code: Select all

session["RET_VAL_FROM_ENCRYPT"] = EncryptDecrypt.EncryptDecrypt.Encrypt(sToEncrypt);
So, can you please edit your C# custom action code accordingly and test again the scenario?

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
vasu0020
Posts: 22
Joined: Wed Aug 27, 2014 9:55 am

Re: Return value from c# custom action to Property

Daniel wrote:Hello Srinu,

Please keep in mind that in order to get an installer property (i.e. VAL_TO_ENCRYPT) within your C# custom action you should use a statement like this:

Code: Select all

sToEncrypt = session["VAL_TO_ENCRYPT"];
Also, in order to set an installer porperty (i.e. RET_VAL_FROM_ENCRYPT) you should use a statement like this:

Code: Select all

session["RET_VAL_FROM_ENCRYPT"] = EncryptDecrypt.EncryptDecrypt.Encrypt(sToEncrypt);
So, can you please edit your C# custom action code accordingly and test again the scenario?

All the best,
Daniel
I tried as you suggested, but it didn't work. I am able to encrypt the password and save in a session variable with the below line of code-
session["RET_VAL_FROM_ENCRYPT"] = EncryptDecrypt.EncryptDecrypt.Encrypt(sToEncrypt);
i am unable to get this value in to advanced installer.

I have attached my AI project to this post for reference please do the needful.

Thanks in advance
Srinu Gatla
Attachments
Password Encryption.zip
(612.47 KiB) Downloaded 324 times
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Return value from c# custom action to Property

Hello Srinu,

This happens because you have added your C# custom action after the "Install Execution Stage -> Add Resources" action group (after the Update XML custom action is executed). Can you please move your custom action before "Install Execution Stage -> Add Resources" action group, rebuild your project and test it again?

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”