This object encrypts strings in a format that the QTP SetSecure function understands. Encrypt is the only method provided by the object.
'Encrypt the string
myVar = Crypt.Encrypt("QTPText")
The above statement will assign myVar a value which looks something like
"456955244855c54535454f5455784456f66446s7r464a64r64kj464b6467h443g3234"
This value produced by Crypt.Encrypt is not constant because encrypting the same string again generates a different encrypting string. Now the question arises that when should this capability be used? Consider a script which is executed on a tester's PC with the results sent to others. Is the script has a step top enter a password:
'Set the text in the WebEdit
Browser("Browser").Page("Page").WebEdit("password").Set "QTP"
Then this step will appear in the result summary and will include the "QTP" value. This could compromise security, so let's replace the above statement with a new one:
'Encrypt and then set the password
sEncryptPassword = Crypt.Encrypt("QTP")
Browser("Browser").Page("Page").WebEdit("password").SetSecure sEncryptPassword
Now the password won't appear in the test result summary as we are using the secure mode of setting the password.
NOTE: We can also create an instance of the crypt object is VBScript using the following code :
Set myCrypt = CreateObject("Mercury.Encrypter")