Converting a string to Base64 in echelon

Hi

 

Im trying to convert a string (combination of mobile number and password) to a Base64 string. I seem to be running into a couple of issues (please excuse my ignorance, I am totally new to Python):

1. I have tried to import the following library (import base64), but I get an error saying "No module named base64".

2. I have read some conflicting info. Some say that (base64.b64encode) only works on byte arrays, while others are using it with a string. Do I need to convert my string to a byte array first, or will this work on a string.

3. Does anyone by chance have  a snippet or a script showing how to do this.

Thanks

Drew

Have more questions? Submit a request

2 Comments

  • 0
    Avatar
    smilliken

    Hi Drew,

    IronPython is an implementation of the Python language, that targets the .NET framework. As a result, you won’t be able to use Python specific libraries, but should use the .NET classes/namespace. Below is an example of how to do this:

    clr.AddReference("System.Text")

    from System import Convert

    from System.Text import ASCIIEncoding

     

    toEncodeAsBytes = ASCIIEncoding.ASCII.GetBytes(toEncode)

    encodedString = Convert.ToBase64String(toEncodeAsBytes)

     

    Thanks,
    Scott

     

  • 0
    Avatar
    Drew Murphy

    Thanks Scott, that worked.

Please sign in to leave a comment.
Powered by Zendesk