Here we will discuss encryption and decryption with an example in asp.net core.We use Protect() and Unprotect() methods of IDataProtector interface in ASP.Net Core to encrypt and decrypt respectively.
Using IDataProtector we can encrypt/decrypt querystring, any sensitive data, connection string and etc.
So Lets start,
Create a class as shown below:-
using Microsoft.AspNetCore.DataProtection;
namespace MyDemo
{
public class CustomIDataProtection
{
private readonly IDataProtector _protector;
public CustomIDataProtection(IDataProtectionProvider provider)
{
_protector = provider.CreateProtector("YOURSECRETKEY"); // you can pass any string as key
}
public string ProtectData(string data)
{
return _protector.Protect(data);
}
public string UnProtectData(string data)
{
return _protector.Unprotect(data);
}
}
}
Now In your PageModel or Controller use above class as shown below:-
public class IndexModel : PageModel
{
private readonly CustomIDataProtection _protector;
public IndexModel(CustomIDataProtection provider)
{
_protector = provider;
}
public void OnGet()
{
string encrypted= _protector.ProtectData("mysensitivedata");
string decrypted= _protector.UnProtectData(encrypted);
}
}
Thats it !!
Execute Javascript function in a Javascript file in Automation Anywhere
Here, I will show you an example on how to Execute Javascript function in a Javascript file in Automation Anywhere.
Steps are below:-
Step-1) Lets create a javascript file as scripts.js as shown below:-
//-------------JS Funtion to get dates between two dates---------------
WScript.StdOut.WriteLine(fnGetDateListInDateRange());
function fnGetDateListInDateRange() {
var addDays = WScript.Arguments.Item(2);
var startDate = WScript.Arguments.Item(0);
var endDate = WScript.Arguments.Item(1);
startDate = new Date(startDate);
endDate = new Date(endDate);
//
if (startDate > endDate)
{
return "-1";
}
//
var outputDate = new Array();
var tmpDate = new Date(startDate);
do {
outputDate.push(new Date(tmpDate));
tmpDate.setDate(tmpDate.getDate() + parseInt(addDays));
} while (tmpDate <= endDate);
//
return outputDate;
}
Step-2) Now call scripts.js using RunScript command in AA as shown below:-

Step-3) Run the task
Thats it !