Base64 Encode with Attachmate Extra! Basic macro

86 views Asked by At

I'm working with an Attachmate (MicroFocus) Extra! Basic macro and have a need to encode a string to Base64 for rudimentary password protection. The code below is what keeps popping up in searches. I'm not sure if I'm missing a declaration or lib, but I'm stuck on this issue. Can anyone point me in the right direction to Encode Base64 in Extra! Basic, or any other simple hash.

Function EncodeBase64(text$)
    Dim b
    With CreateObject("ADODB.Stream")
        .Open: .Type = 2: .Charset = "utf-8"
        .WriteText text: .Position = 0: .Type = 1: b = .Read
        
        With CreateObject("Microsoft.XMLDOM").createElement("b64")
            .DataType = "bin.base64": .nodeTypedValue = b
         ' EncodeBase64 = Replace(Mid(.text, 5), vbLf, "")

        End With
        .Close
    End With
End Function
1

There are 1 answers

3
Gustav On

You can use function TextBase64:

' Convert and return a plain string as a Base64 encoded string.
' Generic function.
'
' 2021-10-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function TextBase64( _
    ByVal Text As String) _
    As String
    
    Dim Text64          As String

    Text64 = ByteBase64(StrConv(Text, vbFromUnicode))
    
    TextBase64 = Text64

End Function

It is a wrapper only. The full code is way too much to post here, but can be found in module BCrypt.bas located at my GitHub project VBA.Cryptography including full documentation.

Note please, that Base64 encoding in no way protects your passwords. However, the project and the articles detail how to apply full protection using current methods.