How to Encyrpt and Decrypt Password in UFT?
Requirement: We aim to secure our application’s login password, such as for an Oracle database. Instead of sharing the password directly, we want to encrypt it. When using the SQL query, the password should be decrypted at runtime.
Solution: First, we’ll encrypt the password and then decrypt it.
Encryption:
Approach 1:
- Using Crypt Utility Object
- Method: Encrypt
- Syntax: [Syntax details]
- Code: [Code details]
- Code Example: [Code example details]
Approach 2:
- Using Password Encoder (Tool in UFT)
- Open Command Prompt and type the path “C:Program Files (x86)HPUnified Functional TestingbinCryptonApp.exe” to run it.
- Navigate to: Start > All Programs > HP Software > HP Unified Functional Testing > Tools > Password Encoder. (Note: Path might differ based on the UFT installation folder.)
- Click on the “Generate” button to create the encrypted password.
Decryption: With the encrypted password in hand, we need to decrypt it before using it in our SQL query connection string. UFT internally uses the “SetSecure” method for decryption, which automatically decrypts the password. We’ll use this method for decryption.
Code:
'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