<(UFT) Support tip> How to use Encrypt/Decrypt methods available on API testing from a GUI Test
I recently got this question and I’d like to share the answer with the community.
API Testing offers an encryption mechanism that enables the user to encrypt or decrypt strings (like passwords) through the EncryptionMngr object.
You can get more information on how to use these methods on API tests from UFT’s online help center:
The option of using these methods from GUI tests is useful in scenarios where we want to share encrypted data between API and GUI tests.
The below sample snippet shows how to accomplish this:
'Get the path of the ST utilities dll file from your UFT machine lib = Environment("ProductDir") + "\bin\HP.Utt.St.Utilities.dll" 'ST Utilities dll is .net assembly, so we can create an instance of it using DOTNetFactory Set STUtilities = DOTNetFactory.CreateInstance("HP.Utt.St.Utilities.Encryption.EncryptionManager", lib).Instance 'Here an example on how to encrypt a string. The ecrypted value will look like this: w2DbF/PiKci8CKBGp2Buww== myEncryptedValue = STUtilities.Encrypt("Alvaro") 'Here an example on how to decrypt it msgbox STUtilities.Decrypt(myEncryptedValue, true)
If you find this useful, mark Kudos.