Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypt and Decrypt passwords in Selenium Webdriver

I am working on a simple test scenario which checks the successful login into facebook, with my own credentials.I want the password to be encrypted and login with the same. How can this be done? Some code snippet would be helpful.Would decryption also be required? I am looking for somewhat the same capability like QTP has. My code snippet is as below

    WebDriver driver = new FirefoxDriver();
    driver.get("https://www.facebook.com/");
    driver.findElement(By.id("email")).sendKeys("[email protected]");
    driver.findElement(By.id("pass")).sendKEys("encrypted password)//would want the encrypted pwd        

Pl help

like image 751
jchan2021 Avatar asked Nov 28 '25 05:11

jchan2021


2 Answers

This answer may be late but please try Apache's Base64 Class please try the below code for the same

WebElement pwd = driver.findElement(By.id("j_password"));

byte[] encodedBytes = Base64.encodeBase64("Password".getBytes());
System.out.println("encodedBytes "+ new String(encodedBytes));

byte[] decodedBytes = Base64.decodeBase64(encodedBytes);
System.out.println("decodedBytes "+ new String(decodedBytes));

pwd.sendKeys(new String(encodedBytes));

Hope this will work ....

like image 69
Toni Ramchandani Avatar answered Nov 29 '25 18:11

Toni Ramchandani


If you are looking for encryption and decryption mechanism in Java similar to what qtp provides, that is not possible unfortunately. In Java you can use 'Base64' class or some other mechanism too, to encrypt and decrypt the password, but anyone having access to your code can easily figure out original value for password. As a matter of fact, by using Base64 you only avoid storing the password in it's original form. If it's a question whether anyone can pull the original password, then answer is yes, the person having access to the code can easily do that. In qtp it's different, tool itself generates the encryption which only inbuilt libraries has access to and while decryption, only tool can decrypt that. Any person can not figure out original password. Thats a very strong feature qtp provides, when it comes to automation. I agree too. but un-fortunately it's not available in selenium.

like image 44
Ajay Singh Avatar answered Nov 29 '25 17:11

Ajay Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!