How to Decrypt an Encrypted Password in QTP
To encode or encrypt a password, QTP provides Encrypt method and Password Encoder tool. But what happens when a user wants to find out the decrypted (original) value of an encrypted password? QTP doesn’t provide a direct way to obtain the decrypted/decoded password.
The only method available is the SetSecure method which internally decrypts the value and sets it in the password fields.
The trick here is to use SetSecure method to decrypt the password but instead of entering the decrypted value in a password field (which displays text as ***), we will enter the value in a normal text field (which will display the text to the user in readable format). Lets see how this can be done.
Our Approach to Decrypt Password (In Brief)
a) Encrypt a password.
b) Create a VBScript InputBox.
c) Use the SetSecure method to write the decrypted value in the text field inside the InputBox
Detailed Steps to Decrypt Password
a) Let’s take an original password first (say – qwerty). When we encrypt this password using Password Encoder tool in QTP, we get 4e63eb23edd909f721d59eaa98fecb6d82a7 as the decrypted password (see below pic). Our aim is to use the decrypted password and obtain back the original password.
|Encrypted String for Password – qwerty|
b) Now the next step is to create an InputBox. To do this, write the following text in a notepad –
InputBox “The text box below displays the Decrypted Password”, “Decrypt Password”
Save the notepad as .vbs file in the local disk (In this example, we are saving the notepad as ‘DecryptPwd.vbs’ in ‘D:’ drive). If we execute the ‘DecryptPwd.vbs’ file, it would display the InputBox as shown below.
|InputBox to display the Decrypted (original) Password|
c) The final step is to use SetSecure method to display the original password in the InputBox. For this write the following code in QTP.
'Execute the .vbs code to display the InputBox SystemUtil.Run “D:DecryptPwd.vbs” 'Type the decrypted password in WinEdit field of InputBox Dialog("nativeclass:=#32770","text:=Decrypt Password").WinEdit("nativeclass:=Edit").SetSecure "4e63eb23edd909f721d59eaa98fecb6d82a7"
When you execute this code, the InputBox gets opened and the SetSecure method enters the original decrypted password in the InputBox as displayed in the figure below. Now you can note down this decrypted password and use it wherever required.
|The InputBox displays the original password – qwerty|
Note: It is not necessary that the user uses VBScript InputBox to display the decrypted password. The logic van be written for any application where a text field is available.