Quality Testing

Quality is delighting customers

Can anyone suggests how to write a java code for encryption of the password in the selenium Eclipse.

Hi,

Can anyone suggests how to write a java code for encryption of the password in the selenium Eclipse.

Iam struck with the encryption of the password.

Thanks

Anil

Views: 797

Reply to This

Replies to This Discussion

Dear Anil,

Can you be clear on what you are looking for? and why you want to do it and which scenario.

Regards!

Master

I have a password -anil

in QTP we use setsecure and give encode string the same way do we have anything to give in selenium instead of directly giving the hard code value-anil

Sample Code
  1. PasswordService.java
  2.  
  3.  
  4.  
  5. import java.io.UnsupportedEncodingException;
  6. import java.security.MessageDigest;
  7. import java.security.NoSuchAlgorithmException;
  8. //import org.myorg.SystemUnavailableException;
  9. import sun.misc.BASE64Encoder;
  10. import sun.misc.CharacterEncoder;
  11.  
  12. public final class PasswordService
  13. {
  14.   private static PasswordService instance;
  15.  
  16.   public PasswordService()
  17.   {
  18.   }
  19.  
  20.   public synchronized String encrypt(String plaintext) throws Exception
  21.   {
  22.     MessageDigest md = null;
  23.     try
  24.     {
  25.       md = MessageDigest.getInstance("SHA"); //step 2
  26.     }
  27.     {
  28.       throw new Exception(e.getMessage());
  29.     }
  30.     try
  31.     {
  32.       md.update(plaintext.getBytes("UTF-8")); //step 3
  33.     }
  34.     {
  35.       throw new Exception(e.getMessage());
  36.     }
  37.  
  38.     byte raw[] = md.digest(); //step 4
  39.     String hash = (new BASE64Encoder()).encode(raw); //step 5
  40.     return hash; //step 6
  41.   }
  42.  
  43.   public static synchronized PasswordService getInstance() //step 1
  44.   {
  45.     if(instance == null)
  46.     {
  47.        instance = new PasswordService();
  48.     }
  49.     return instance;
  50.   }
  51. }
  52.  
  53.  
  54.  
  55.  
  56. PasswordUtil.java
  57.  
  58.  
  59.  
  60. public final class PasswordUtil
  61. {
  62.          private PasswordUtil()
  63.          {
  64.          }
  65.                 public static void main(String a[]) throws Exception
  66.                 {
  67.                  PasswordService ps=new PasswordService();
  68.                  System.out.println(ps.encrypt("yourpassword"));//readthis using selenium
  69.                  }
  70. }

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service