Forum Discussion

Said's avatar
Said
Contributor
6 years ago
Solved

Base64 decode password

Hi All,

 

I have a a project property that has a password that I use in a request. In the password field of the request I use syntax below to get password in request:

${#Project#servicePwd}

This works perfect. Now I would like to use base64 encoded password and decode this password with syntax below:

${=java.util.Base64.getDecoder().decode(${#Project#servicePwd})}

But When I use this syntax I get invalid userid / password error. What am I doning wrong? How can I use encoded passwords?

 

Thanks in advance!

  • I think you could get what you want with this snippet of code:

     

    ${= new String (context.testCase.testSuite.project.getPropertyValue("servicePwd").decodeBase64() )}

5 Replies

  • Radford's avatar
    Radford
    Super Contributor

    Just to clarify, when you say "I would like to use base64 encoded password and decode" do you mean that the property ${#Project#servicePwd} is a Base64 encoded string and you want to convert this to plan text to send to your service, or vice versa?

     

    As an aside Groovy contains it's own methods to encode & decode Base64 strings, you shouldn't need to use the java.util library. See the following page for details:

     

    http://mrhaki.blogspot.com/2009/11/groovy-goodness-base64-encoding.html

    • Said's avatar
      Said
      Contributor

      Exactly, I want to decode the password stored in ${#Project#servicePwd}

       

      And thanks for the groovy tip. I will look into it.

      • Radford's avatar
        Radford
        Super Contributor

        Just one more point, I was wondering why you had a Base64 encoded property? Are you just trying to obscure the password, so somebody can't just view it? If so are you aware that Ready API has several feature to protect sensitive data? I've personally never used them, but they are described on the following page:

         

        https://support.smartbear.com/readyapi/docs/testing/best-practices/secure.html

         

        In particular check out the section "Encrypt Individual Properties".