Skip to content

Instantly share code, notes, and snippets.

@sadhasivam
Created April 9, 2018 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sadhasivam/5c1d530f7cdbf912ad4582ca4ed9af58 to your computer and use it in GitHub Desktop.
Save sadhasivam/5c1d530f7cdbf912ad4582ca4ed9af58 to your computer and use it in GitHub Desktop.
GenerateWSPassword.java
package client;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import java.io.PrintStream;
import java.security.MessageDigest;
public class GenerateWSPassword
{
public GenerateWSPassword() {}
public static void main(String[] args)
{
String nonce = "";
String created = "";
String passwdDigest = "";
try {
String password = "";
if (args.length == 0) {
System.out.println("Password should be provided.");
System.out.println("Usage ");
System.out.println("java -jar orderws-client.jar <password to test>");
System.out.println("Using default <password>");
System.exit(0);
} else {
password = args[0];
}
System.out.println("Using password ****" + password + "****");
byte[] nonceValue = new byte[16];
java.security.SecureRandom.getInstance("SHA1PRNG").nextBytes(nonceValue);
nonce = new String(Base64.encode(nonceValue));
java.util.Date date = new java.util.Date();
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
created = formatter.format(date);
byte[] b1 = nonce != null ? Base64.decode(nonce) : new byte[0];
byte[] b2 = created != null ? created.getBytes("UTF-8") : new byte[0];
byte[] b3 = password.getBytes("UTF-8");
byte[] b4 = new byte[b1.length + b2.length + b3.length];
int offset = 0;
System.arraycopy(b1, 0, b4, offset, b1.length);
offset += b1.length;
System.arraycopy(b2, 0, b4, offset, b2.length);
offset += b2.length;
System.arraycopy(b3, 0, b4, offset, b3.length);
MessageDigest sha = MessageDigest.getInstance("SHA-1");
sha.reset();
sha.update(b4);
passwdDigest = Base64.encode(sha.digest());
System.out.println("====================================================");
System.out.println("password-digest \t: " + passwdDigest);
System.out.println("nonce \t\t\t: " + nonce);
System.out.println("created value \t\t: " + created);
System.out.println("====================================================");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment