Encrypt/Decrypt Base64 string in TestComplete
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Encrypt/Decrypt Base64 string in TestComplete
Hi,
I'm in need of decrypting a Base64 string in a Testcomplete script. The value is coming from a datafile. Is it possible to use a javascript method like atob() or btoa(), within testcomplete for this purpose? Or is there any other option?
Thanks,
~Roshan
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you have dotNet extension installed, you could try something like
var encodedText = dotNET.System.Convert.ToBase64String("Hello World");
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @rraghvani, thanks for the suggestion. It seemed working. However, I wanted to convert using 'FromBase64String', which gave me the byte array of the converted string. And had troubles converting the byte array to the string. At the and created following function to invoke a PowerShell command. That did the trick for me.
function b64ToString (str){
var ps = dotNET.System_Management_Automation.PowerShell.Create();
ps.AddScript( "[Text.Encoding]::Utf8.GetString([Convert]::FromBase64String('"+str+"')) | Out-String");
var results = ps.Invoke();
for (i = 0; i < results.Count; i++)
{
convertedString = results.Item(i).ImmediateBaseObject;
}
return convertedString;
}
