How to Encyrpt and Decrypt Password in UFT? – User friendly Tech help
Requirement:-
n
nWe don’t want to share our application(say Oracle database) login password , but rather encrypt it and while using the SQL query we need it to be decrypted at runtime.
n
nSolution:-
n
Firstly we will Encrypt the password and then decrypt it.
n
Encryption:-
n
nApproach 1:-
n
nUsing Crypt utlity Object.
nMethod used :- Encrypt n
Syntax |
n
Code:-
n
Code Example |
n
Approach 2:-
n
Using Password Encoder (Tool in UFT)
n
Open:-
n
n
1. Open Command Prompt and Type the path “C:Program Files (x86)HPUnified Functional TestingbinCryptonApp.exe” to Run it.
n
n2.Start > All Programs > HP Software > HP Unified Functional Testing >Tools >Password Encoder
n
nNote: Path can vary based on the UFT installation folder.
n
nClick on Generate button to create the encrypted password.
n
n
Password Encoder |
nDecryption:-
n
Now we have the encrypted password, we need it to be decrypted before we can utilize in our SQL query connection string.
n
nHint:- For decrypting the password UFT, internally uses the “SetSecure” method, which automatically decrypt it .So we will leverage this approach to achieve the decryption.
n
nCode:-
n
n
'Password Encryption
Dim sPwd ,sEPwd,sDPwd
sPwd = "uftHelp"sEPwd = Crypt.Encrypt(sPwd)
Msgbox sEPwd,,"Encryption"
'Password DecryptionsDPwd = fn_DecryptMe(sEPwd)
Msgbox sDPwd,,"Decryption"
'*******************************************Function************************************************
'Function Name:- fn_DecryptMe
'Function Description:- Decrypt the given string
'Input Parameters:- Encrypted String
'Output Parameters:- Decrypted value
''**************************************************************************************************
Public Function fn_DecryptMe(sEPwd)
'Closing the opened IE instance
Systemutil.CloseProcessByName "iexplore.exe"
'Launching the IE
'Mode = 7 (Displays the window as a minimized window. The active window remains active)
SystemUtil.Run "C:Program Files (x86)Internet Exploreriexplore.exe", "www.google.com", "","",7
'Setting the value in Google url using SetSecure
If Browser("micclass:=Browser", "index:=0").WinEdit("micclass:=WinEdit", "index:=0").Exist Then
Browser("micclass:=Browser", "index:=0").WinEdit("micclass:=WinEdit", "index:=0").SetSecure sEPwd
'Taking the Decrypted Value
fn_DecryptMe = Browser("micclass:=Browser", "index:=0").WinEdit("micclass:=WinEdit", "index:=0").GetROProperty("text")
Else
Print "Decryption failed, Please try again" fn_DecryptMe = sEPwd
End If
'Closing the opened IE instance
Systemutil.CloseProcessByName "iexplore.exe"
End Function