List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:md5.demo.MD5Demo.java
public static void main(String[] args) { String input = "123456"; try {/* www . j a va2s. c o m*/ MessageDigest messageDigest = MessageDigest.getInstance("MD5"); byte[] output = messageDigest.digest(input.getBytes()); String outString = Hex.encodeHexString(output); System.out.println(outString); } catch (NoSuchAlgorithmException ex) { ex.printStackTrace(); } }
From source file:com.jabyftw.StringLengthTest.java
public static void main(String[] args) { try {// w ww. j a va2 s .co m // Make it the range of the password for (int length = 4; length <= 26; length++) { String string = RandomStringUtils.random(length, true, true); String encryptedString = Util.encryptString(string); System.out.println("Encrypting a " + length + " string resulted on a " + encryptedString.length() + " encrypted length string: " + string + " -> " + encryptedString); } // Set variables for testing String IN = "N3VIg4dv1FO0LQuauHeuC6", PRE_ENCRYPTED_OUT = "4be9cc85bf5abc7cb99019a84256e938fbc4fbafa80598b297dc8bc3e22f11dd"; // Testing if it is safe on every example String encryptionOut = Util.encryptString(IN); System.out.println("\nTesting safety: (" + encryptionOut + " == " + PRE_ENCRYPTED_OUT + " )? " + encryptionOut.equals(PRE_ENCRYPTED_OUT)); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } // Test passed, every encrypted string is 64 letters length }
From source file:com.coinkite.CoinkiteSigningRequestInterceptor.java
public static void main(String[] args) { CoinkiteSigningRequestInterceptor coinkiteSigningRequestInterceptor = new CoinkiteSigningRequestInterceptor(); try {/* www . j av a 2s.co m*/ String[] strings = coinkiteSigningRequestInterceptor.createSigAndTimestamp("/v1/pubnub/send"); System.out.println(strings[0]); System.out.println(strings[1]); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } }
From source file:MD5.java
public static void main(String[] args) { //String password = args[0]; String password = "test"; MessageDigest digest = null;// ww w. ja v a 2 s . c o m try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } try { digest.update(password.getBytes("UTF-8")); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } byte[] rawData = digest.digest(); StringBuffer printable = new StringBuffer(); for (int i = 0; i < rawData.length; i++) { printable.append(carr[((rawData[i] & 0xF0) >> 4)]); printable.append(carr[(rawData[i] & 0x0F)]); } String phpbbPassword = printable.toString(); System.out.println("PHPBB : " + phpbbPassword); System.out.println("MVNFORUM : " + getMD5_Base64(password)); System.out.println("PHPBB->MVNFORUM : " + getBase64FromHEX(phpbbPassword)); }
From source file:org.opennms.protocols.vmware.VmwareConfigBuilder.java
public static void main(String[] args) throws ParseException { String hostname = null;/*from w w w.j a va2 s . c o m*/ String username = null; String password = null; String rrdRepository = null; final Options options = new Options(); options.addOption("rrdRepository", true, "set rrdRepository path for generated config files, default: '/opt/opennms/share/rrd/snmp/'"); final CommandLineParser parser = new PosixParser(); final CommandLine cmd = parser.parse(options, args); @SuppressWarnings("unchecked") List<String> arguments = (List<String>) cmd.getArgList(); if (arguments.size() < 3) { usage(options, cmd); System.exit(1); } hostname = arguments.remove(0); username = arguments.remove(0); password = arguments.remove(0); if (cmd.hasOption("rrdRepository")) { rrdRepository = cmd.getOptionValue("rrdRepository"); } else { rrdRepository = "/opt/opennms/share/rrd/snmp/"; } TrustManager[] trustAllCerts = new TrustManager[1]; trustAllCerts[0] = new TrustAllManager(); SSLContext sc = null; try { sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, null); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HostnameVerifier hv = new HostnameVerifier() { @Override public boolean verify(String urlHostName, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(hv); VmwareConfigBuilder vmwareConfigBuilder; vmwareConfigBuilder = new VmwareConfigBuilder(hostname, username, password); try { vmwareConfigBuilder.generateData(rrdRepository); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.tcs.ebw.security.EBWSecurity.java
public static void main(String args[]) { try {/*from ww w.jav a2 s. c o m*/ EBWSecurity sec = new EBWSecurity(); String testData2 = "Pramodh B Somashekara 231259 Channels !@#$%^&*()"; if (args.length > 0) testData2 = (String) args[0]; if (testData2 == null) { System.out.println("No Arguements in command line...Continuing with 'ELECTUSR'"); testData2 = "ELECTUSR"; } byte[] enc; System.out.println("----------------ENCRYPTION-------------"); System.out.println("Original String:" + testData2); /** Set IMRS Key here **/ sec.setSecretKey(sec.getSecretKey()); testData2 = (new String(Base64.encodeBase64(sec.encryptSymmetric(testData2.getBytes())))); System.out.println("After Base64 Encode:" + testData2); testData2 = java.net.URLEncoder.encode(testData2, "utf-8"); System.out.println("Encrypted[Base64+EncryptAlgo+URLEncoded][" + testData2 + "]"); System.out.println("---------------DECRYPTION--------------"); System.out.println("Encrypted[Base64+EncryptAlgo+URLEncoded]" + testData2); testData2 = java.net.URLDecoder.decode(testData2, "utf-8"); testData2 = new String(sec.decryptSymmetric( Base64.decodeBase64(java.net.URLDecoder.decode(testData2, "utf-8").getBytes()))); System.out.println("Decrypted[Base64+EncryptAlgo][" + testData2 + "]"); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchPaddingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadPaddingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidKeyException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalBlockSizeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.scantegrity.scanner.Scanner.java
/** * Main Logic loop.//from ww w .j a v a 2 s .co m * * @param args CLI flags */ public static void main(String[] args) { processCmdLine(args); //Create the locations we should output files too createOutputDirectories(); //register logging handlers if any c_myId = c_config.getPollID(); c_log = new Logging(c_outDirs, c_myId, Level.FINEST); c_log.log(Level.INFO, "Logging Intialized"); c_log.log(Level.INFO, "Scanner ID Number: " + c_myId); c_log.log(Level.INFO, "Initializing Cryptographic hash and rng."); try { c_hash = MessageDigest.getInstance("SHA1"); } catch (NoSuchAlgorithmException l_e) { l_e.printStackTrace(); c_hash = null; c_log.log(Level.SEVERE, "Unable to initialize hash. Reason: " + l_e.getMessage()); } try { c_csprng = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException l_e) { l_e.printStackTrace(); c_csprng = null; c_log.log(Level.SEVERE, "Unable to initialize RNG. Reason: " + l_e.getMessage()); } //init counters c_scanCount = new Integer(0); c_ballotCount = new Integer(0); c_errorCount = new Integer(0); checkForPreviousCounters(); writeCounters(); //init ballot storage c_ballotIds = new Vector<Integer>(); //TODO: Change this size to be variable... c_store = initializeBallotStore(c_outDirs, 100 * 1024 * 1024); //start the election c_log.log(Level.SEVERE, "Election Started"); playAudioClip(2); //main loop //TODO: terminating condition, button, or special ballot??? while (true) { BufferedImage l_ballotImg[] = null; Ballot l_ballot = null; //process image into ballot l_ballotImg = getBallotImages(); if (l_ballotImg == null || (l_ballotImg[0] == null && l_ballotImg[1] == null)) continue; //scan count c_scanCount++; writeCounters(); playAudioClip(0); for (int l_c = 0; l_c < l_ballotImg.length; l_c++) { //Ignore empties if (l_ballotImg[l_c] == null) { c_log.log(Level.WARNING, "Only 1 ballot object returned." + " Make sure the scanner supports duplex"); continue; } //Ignore blank pages if (DrunkDriver.isDrunk(l_ballotImg[l_c], 10)) continue; l_ballot = getBallot(l_ballotImg[l_c]); if (l_ballot == null) continue; //update ballot counter c_ballotCount++; writeCounters(); l_ballot.setScannerId(c_myId); if (isDuplicate(l_ballot)) { c_log.log(Level.WARNING, "Duplicate Ballot detected. ID : " + l_ballot.getId()); l_ballot.setCounted(false); l_ballot.addNote("Duplicate Ballot"); } //check if the ballot is a "starting ballot" //check if the ballot is a "closing ballot" //else saveBallot(l_ballot); } //resume scanning } //end election (ballot handler) //turn off storage //disconnect devices //turn off log //quit //endElection(); }
From source file:Main.java
public static byte[] calculateSHA1(byte[] data) { try {/*from w w w. ja v a 2s . c om*/ MessageDigest md = MessageDigest.getInstance("SHA1"); return md.digest(data); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static byte[] md5(byte[] bytes) { try {//w w w . j a v a 2 s . co m MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.update(bytes); return messageDigest.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
From source file:AddSHA1.java
public static String SHA1(String inStr) { MessageDigest md = null;/*from w w w. j a va 2s. co m*/ String outStr = null; try { md = MessageDigest.getInstance("SHA-1"); //SHA-1?MD5 byte[] digest = md.digest(inStr.getBytes()); //byet[]?String outStr = bytetoString(digest); } catch (NoSuchAlgorithmException nsae) { nsae.printStackTrace(); } return outStr; }