CLR - Base64 conversion for REST query

Started by stanl, July 16, 2020, 05:21:23 PM

Previous topic - Next topic

stanl

I'll be working on a script to return JSON from a REST API. I've already confirmed TLS 1.2 as the protocol [took Tony's idea from a previous post] but have to send username and password as Base64. Surprisingly simple to do in the CLR; test is below
Code (WINBATCH) Select


;CLR - create Base64 user/pw for web rest request
user = 'myuser'
pw   = 'mypassword'
ObjectClrOption("useany","System")
oEncode = ObjectClrNew('System.Text.Encoding')
oCvt    = ObjectClrNew('System.Convert')
oAsc    = oEncode.ASCII
bUser   = oCvt.ToBase64String(oAsc.GetBytes(user))
bPW     = oCvt.ToBase64String(oAsc.GetBytes(pw))
message("Base64",BUser:@LF:BPW)


aUser = oAsc.GetString(oCvt.FromBase64String(bUser))
aPW   = oAsc.GetString(oCvt.FromBase64String(bPW))
message("Back to ASCII",aUser:@LF:aPW)


oCvt    = 0
oAsc    = 0
oEncode = 0
Exit