How do you handle data encryption in Ranorex?

Class library usage, coding and language questions.
gilbar16
Posts: 109
Joined: Wed Mar 26, 2014 6:23 pm

How do you handle data encryption in Ranorex?

Post by gilbar16 » Wed Mar 26, 2014 6:52 pm

Hello, I am a new Ranorex Forum user and this is my first post.
I did Search for "data encryption" and did not find any result that answers my question.
I was told that there is no built-in method/function in Ranorex for doing data encryption similar to the .SetSecure method provided in QTP/UFT.

Since Ranorex has been around for awhile, I have a feeling that someone out there already found a way to encrypt data via coding. If you are one of them, do you mind sharing a sample code that can be used to encrypt data such as passwords and social security numbers?

Thank you very much.
Gilbert

mzperix
Posts: 137
Joined: Fri Apr 06, 2012 12:19 pm

Re: How do you handle data encryption in Ranorex?

Post by mzperix » Fri Mar 28, 2014 8:55 am

Since Ranorex based on C# programming language, you can make data encrytion in user code using the .NET built-in encryption methods.

I made a small search on google, and the first relevant find is: http://stackoverflow.com/questions/9346 ... in-c-sharp

I managed to solve most of my problems, by using the full power of .NET :)

I think Ranorex made a good choice of this programming language, since if a feature is not supported by Ranorex, still there is .NET and coding to solve our porblem.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How do you handle data encryption in Ranorex?

Post by Support Team » Fri Mar 28, 2014 10:39 am

Hello gilbar16,

As you are already mentioned there is currently no build-in method for data encryption.

As a workaround you can use following methods. The main component ProtectedData.Protect() is provided by the .NET-framework itself so there are no additional libraries necessary:

Code: Select all

using System.Security.Cryptography;
public string Encrypt(string plainText)
    {
        if (plainText == null) throw new ArgumentNullException("plainText");
		
        //encrypt data
        var data = Encoding.Unicode.GetBytes(plainText);
        byte[] encrypted = ProtectedData.Protect(data, null, DataProtectionScope.LocalMachine);

        //return as base64 string
        return Convert.ToBase64String(encrypted);
    }
        
        
        
        public string Decrypt(string cipher)
    {
        if (cipher == null) throw new ArgumentNullException("cipher");

        //parse base64 string
        byte[] data = Convert.FromBase64String(cipher);

        //decrypt data
        byte[] decrypted = ProtectedData.Unprotect(data, null, DataProtectionScope.LocalMachine);
        return Encoding.Unicode.GetString(decrypted);
    }
Those methods allow you easy encoding and decoding of string values. Hopefully that's what you are looking for :)

Regards,
Robert

gilbar16
Posts: 109
Joined: Wed Mar 26, 2014 6:23 pm

Re: How do you handle data encryption in Ranorex?

Post by gilbar16 » Fri Mar 28, 2014 4:01 pm

Hello Robert,

Thank you for this Ranorex tip!
I'm sure we will use these methods for handling data encryption/decryption in Ranorex in the future, if management decides to purchase Ranorex. Just gathering information now as much as I can and provide these input to management so they can make a wise decision on what test tools to invest in.
We are not allowed to use "bogus" data in most of our testing so test data containing PHI (Patient Health Information) must be carefully handled. When others look at our scripts, these data should shown "encrypted".

I'm also hoping that these methods will help others also, not just me. It will be nice if these methods will be built into future Ranorex versions. (again, similar to that of .SetSecure in QTP/UFT)

Wow! I'm liking this Forum already!!!

Thank you.
Gilbert