Base64 String Decoding Using .NET
Michael C.
El Segundo, CA

Sep 22, 2017
7 Posts

Base64 String Decoding using .NET

Hello,

I am trying to use the mscorlib class "Convert".  One of the methods is "FromBase64String".  When I try to return this into a variant, variant array or even a byte array (randomly big size) I get an compiler error "Unsupported return type: 'FromBase64String' returns an array."

Trying to figure out if I am calling the method incorrectly or if this is a limitation of ATEasy?

Thanks in advance,
Mike

DrATEasy (Ron Y.)
Mission Viejo,

Sep 22, 2017
249 Posts

Re: Base64 String Decoding using .NET

ATEasy does not support functions with array as return type since every language has it own standard for arrays.

You can use a Variant type that holds an array or a Var parameter that return array (like C language arrays).

You can create a .Net wrapper DLL around that function or class that will return it as one of the above types.

Alternatively, you can use use CryptBinaryToString or CryptStringToBinary APIs ( https://msdn.microsoft.com/en-us/library/windows/desktop/aa379887(v=vs.85).aspx, https://msdn.microsoft.com/en-us/library/windows/desktop/aa380285(v=vs.85).aspx) which support BASE 64 encoding

Solution Available
DrATEasy (Ron Y.)
Mission Viejo,

Sep 22, 2017
249 Posts

Re: Base64 String Decoding using .NET

BTW this behavior may change in v10. You may be able to assign it to an object as use it using the array properties  / methods.


Ronnie

Michael C.
El Segundo, CA

Sep 25, 2017
7 Posts

Re: Base64 String Decoding using .NET

Hi Ronnie:

I tried to use the CryptBinaryToString or CryptStringToBinary you suggested and based on reading the MSDN page, it seems like I need to install the CryptoAPI based on CAPICOM. Unfortunately, I am working on a closed system and can't install or make changes to the system without going through all matters of configuration management. FYI the system I am using is running WinXP w/ ATEasy 8.

A work around after googling was using MSXML to get around this issue and MSXML library call was native to ATEasy. All credit to the original author for this now defunct website for the idea:
http://web.archive.org/web/20060527094535/http://www.nonhostile.com/howto-encode-decode-base64-vb6.asp

Basically, you have 2 XML objects, one for the "DOMDocument" and another for the node "IXMLDOMElement". Set node.datatype to "bin.base64", set node.text to base64 string to decode and finally set a Byte array to node.nodeTypedValue.

One extra step I added for ATEasy is to then assign the Byte Array to a string variable. If I tried to assign node.nodeTypedValue directly to a string variable, the variable reads out garbage.

If anyone needs to do any base64 encoding, the steps are more or less the same except the assignments are reversed.

Regards,
Mike

DrATEasy (Ron Y.)
Mission Viejo,

Sep 29, 2017
249 Posts

Re: Base64 String Decoding using .NET

I don't think the API CryptBinaryToString ( https://msdn.microsoft.com/en-us/library/windows/desktop/aa379887%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 ) requires CAPICOM. Where did you see it?

Michael C.
El Segundo, CA

Sep 29, 2017
7 Posts

Re: Base64 String Decoding using .NET

I dropped back into the Crypto top page:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa380255(v=vs.85).aspx

RunTime Requirements states CAPICOM.

Maybe I did something wrong or because I am on WinXP?

Either way I got something to work, if it wasn't for your original post I wouldn't even have thought going down this path.



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]