Last updated: May 18, 2021 11:23
Add the StringEncrypt() class
Follow these steps to add this class to your Selenium project within an Eclipse IDE.
- Download the StringEncrypt() class from the Github link here: https://github.com/brianhclark/StringEncrypt/raw/master/StringEncrypt.java
- Add it as-is as a new class within your Eclipse project. Alternatively, the required methods could be extracted and added to a Utility class if one exists. These are static methods so they don’t require a class instance to be referenced.
- Make sure to reference the correct package once added.
Use the StringEncrypt() class methods
There are two methods included in the StringEncrypt() class:
encryptXOR (String message, String key): This method takes the message to be encrypted and the encryption key as arguments and returns the encrypted string.
decryptXOR(String message, String key): This method takes the encrypted message and the encryption key as arguments and returns the decrypted string.
The anticipated use for this class is to use the encryptXOR method to encrypt sensitive values, either within the code or stored as parameters to be read at runtime. The decryptXOR method would then be leveraged during execution to decrypt any encrypted data at runtime, thereby essentially hiding from visibility any stored sensitive data.
***The encryption key must be saved as there is no mechanism to retrieve or reset a key value if it is lost. ***
Example test case
The following is a simple example highlighting the use of this class within a test case.
Running this test class produces the following output:
As mentioned previously, a utility was created to work as a standalone tool to more easily facilitate the encryption of strings that does not require the creation and execution of an executable java class to generate the encrypted string. This tool can be launched and run independent of eclipse, and only requires a standard JRE installation on Windows machines.
The stringEncryptTool.jar can be downloaded from Github here: https://github.com/brianhclark/StringEncrypt/blob/master/stringEncryptTool.jar?raw=true
Running the jar file will present the user with a small form on which to enter the string to encrypt and the key.
Clicking the button reveals the encrypted string. Click Run Again to encrypt another string, or Copy to Clipboard to load the encrypted string onto the clipboard.
Smart Reporting SDK
The following example code shows how you can hash strings in a Perfecto report using the Smart Reporting SDK:
The following images show the before and after view in the Singe Test Report view: