PASSWORD SECURITY:
The user credentials must be secured so that it cannot be read by unauthorized individual from directly accessing it or misusing of data. To maintain the confidentiality of data choose encoding and decoding techniques.
BASE64:
Base64 is a format taken from a specific MIME-content transfer encoding. This are used when that data needs to be stored and transferred over media. Base64 is commonly used in number of applications including email via MIME, as well as storing complex data in XML / JSON.
ENCODE/DECODE:
An encoding is used to allow arbitrary binary data to be represented in ASCII form. The data is then sent as ASCII and decoded back into binary form by the user. This encoding helps to ensure that the data remains unchanged without modification during the transfer.
Syntax format:
byte[] objArray=Base64.getEncoder().encode(data.getBytes())
byte[] objArray=Base64.getDecoder().decode(data.getBytes())
The above syntax works in the way that all bytes from the input byte array encodes or decodes using the Base64 encoding/decoding scheme and converts the results into a string array.
Methods:
getDecoder(): Returns a Base64.Decoder that decodes using the Basic type base64 decoding scheme.
getEncoder(): Returns a Base64.Encoder that encodes using the Basic type base64 encoding scheme.
Example : TestNG Code Snippet to Decrypt password in Facebook Login:
package CRYPTO;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import java.util.Base64;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
Run All
public class CRYPTOGRAPHY
{
WebDriver driver = null;
@Test
Run | Debug
public void PasswordDecryption() throws InterruptedException
{
driver.findElement(By.id("email")).sendKeys("AmuthaBalakrishnan@yahoo.com");
Thread.sleep(3000);
driver.findElement(By.name("pass")).sendKeys(decryptData("aGVsbG8="));
Thread.sleep(3000);
System.out.println("Password Decrypted");
driver.findElement(By.name("login")).click();
System.out.println("Login");
}
String decryptData(String decrptData)
{
byte[] decodeBytes = Base64.getDecoder().decode(decrptData.getBytes());
return(new String(decodeBytes));
}
@BeforeTest
public void beforeTest() throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\\\Selenium-Driver\\\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
Reporter.log("Page is launched successsfully");
Reporter.log("Page Title : " + driver.getTitle());
Reporter.log("Page Current Url : " + driver.getCurrentUrl());
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(2000);
}
@AfterTest
public void afterTest()
{
driver.close();
}
}
Executed as TestNG class using Maven:
TestNG Console:
Test-output/Emailable-report.html:
Login — www.facebook.com:
Hope You learn something useful. See you in the next blog…