Base64 encoded string
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Base64 encoded string
Hi, as part of a XHR web service call I am testing, I am required to send basic Authorization in the header encoded as Base64.
I couldn't find a way to do this from a Test Complete object so came up with the following using the dotNET object:
function getEncodedCredentials( userName, password ) {
var textBytes = dotNET.System_Text.Encoding.UTF8.GetBytes_2( userName + ":" + password );
var encodedText = dotNET.System.Convert.ToBase64String( textBytes );
return encodedText;
}
which is used such as:
Log.Message( getEncodedCredentials( "fred", "fl1ntst0ne" ) );
My question is this, is their another way to do this in Test Complete that does not require a call to the CLR Bridge?
Regards,
Phil Baird
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I used .Net-based approach in several projects and it worked fine.
However, the following request http://www.google.com/search?q=base64+encode+string+jscript+vbscript returned quite a few results the first of which http://stackoverflow.com/questions/496751/base64-encode-string-in-vbscript looks quite interesting (though I did not verified what people have talked there about).
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Alexei, after a quick look I think I will stick with the .Net approach.
Phil
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Can i get the same equivalent script for decoding a string.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
If your test project is JScript/Java Script/C#Script-based, then the code from https://scotch.io/tutorials/how-to-encode-and-decode-strings-with-base64-in-javascript can be used as it is.
For the project that uses some other language you can put the referenced code into Script Extension and use it from there.
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, But i need the script in this format for decoding too
var string='test';
function main()
{
getEncodedValue(string);
}
function getEncodedValue(string)
{
var textBytes = dotNET.System_Text.Encoding.UTF8.GetBytes_2(string);
var encodedText = dotNET.System.Convert.ToBase64String(textBytes);
// return encodedText;
Log.Message(encodedText);
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
The code I have referenced does not use .Net but is pure Java-based.
If you declare it as a public variable (as in the code sample), then use Base64.encode() to encode the string and Base64.decode() to decode encoded one.
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey Alex,
I need a Function containing only Decoding part in java Script. I refered your Link Containing both encoding and decoding functions together and I'm not able to divide them seperately So can you help me with Seperate functions for both encoding and decode functionalities.
Regards,
Rohit Sen
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rohit,
The referred link contains minified code (with extra spaces and indentations removed). You may expand it with the help of some Java Script formatter (or manually) and remove the part that you don't need.
P.S. Out of curiosity: is it really a problem if encoding function is present in the code?
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
