Wednesday, August 12, 2009

QTP Crypt Object

Crypt Object is used to encrypt strings. Crypt object has an Encrypt method which takes string (string to encrypt) as its parameter.

Example 1 of Crypt Object

Type the below text in a new test in QTP and run it.

pwd = "sachin"
e_pwd = Crypt.Encrypt(pwd)
msgbox e_pwd

Example 2 of Crypt Object

Type the below text in a new test in QTP and run it. You can also write the function (Crypt_Pass) in library and call it from a QTP test.

pas = "Sachin"
MsgBox Crypt_Pass(pas)

Function Crypt_Pass(epas)
Crypt_Pass = Crypt.Encrypt(epas)
End Function

Example 3 of Crypt Object

Use Encrypt outside of QTP in VBScript. Write the below 3 lines in a notepad and save it with .vbs extension and run it from command prompt. For example I saved it as "a.vbs" under c:\ and ran it from command prompt by typing just "a" and pressing enter.

Set a=CreateObject("Mercury.Encrypter")
Msgbox a.encrypt ("Sachin")
Set a=Nothing

Source

Example 4 of Crypt Object

There is one trick by which you can know the encrypted password. For example type the below lines in a new test in QTP and run them. I am entering the encrypted password (in e_pwd) in "Agent Name" field of the Login dialog box which shows up when you open the Flight Application. Entering the encrypted text in a non-secured edit box lets you know the original text.

pwd = "sachin"

e_pwd = Crypt.Encrypt(pwd)

SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest
Professional\samples\flight\app\","open"
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").SetSecure e_pwd
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Type micTab
Dialog("text:=Login").WinEdit("attached text:=Password:").Set "mercury"
Dialog("text:=Login").WinEdit("attached text:=Password:").Type micReturn

Source




Also See:

QTP SystemUtil Vs InvokeApplication
QTP Optional Step
QTP Relative Path
QTP Random Variables