0

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
David
  • 131
  • 1
  • 11

1 Answers1

0

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.

Gustav
  • 53,498
  • 7
  • 29
  • 55
  • Gustav, this is not functional for my application. This is in attachmatre Extra! Basic macro and not VBA. As for security, its not a concern. The password is only to limit access to one menu from computer illiterate users. If they are literate enough to decode Base64 then they are welcome to tweak the macro to their needs. Thanks for your input though. – David Nov 11 '22 at 06:39
  • OK. But why have you tagged your question VBA? – Gustav Nov 11 '22 at 07:45
  • 1
    You got me there. Typos at 3:00AM My apologies. – David Nov 11 '22 at 09:45