List of usage examples for org.apache.commons.codec.digest DigestUtils sha512Hex
public static String sha512Hex(String data)
From source file:net.mohatu.bloocoin.miner.Miner.java
public void mine() throws NoSuchAlgorithmException { // String testString = "dx3NAa"; //dx3NAa257363 while (Main.getStatus()) { String startString = randomString(); System.out.println("Starting: " + startString); for (int counter = 0; counter <= 10000000; counter++) { Main.updateCounter();/* w w w .jav a 2 s .c o m*/ String currentString = startString + counter; String hash = DigestUtils.sha512Hex(currentString); if (hash.startsWith(difficulty)) { new Thread(new Submitter(hash, currentString)).start(); Main.updateSolved(currentString); System.out.println("Success: " + currentString); try { PrintWriter out = new PrintWriter(new BufferedWriter( new FileWriter(System.getProperty("user.home") + "/.bloocoin/solved.dat", true))); out.println(currentString); out.close(); } catch (IOException e) { // Error System.out.println("Unable to save to BLC_Solved.txt, check permissions."); } } if (!Main.getStatus()) { counter = 10000000; System.out.println("STOPPING"); } } } }
From source file:com.lhy.commons.encrypt.service.EncryptService.java
@Override public File createLicenseFile(License license, String licenseFilePath) { License licObj = new License(); licObj.setIpAddress(DigestUtils.sha512Hex(license.getIpAddress())); licObj.setLicenseID(license.getLicenseID()); licObj.setLicenseType(license.getLicenseType()); licObj.setStopTime(// w w w . j av a 2 s .c o m license.getStopTime() == null ? DateUtils.addDays(new Date(), 30) : license.getStopTime()); File licenseFile = null; try { licenseFile = new File(licenseFilePath + File.separator + LicenseFileName); ObjectOutput out = new ObjectOutputStream(new FileOutputStream(licenseFile)); out.writeObject(licObj); out.close(); } catch (FileNotFoundException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } return licenseFile; }
From source file:com.mimp.hibernate.HiberMain.java
public ArrayList<Object> usuario(String user, String pass) { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();/*from w ww . j a v a2s.co m*/ Personal personal; Entidad entidad; Familia familia; pass = DigestUtils.sha512Hex(pass); ArrayList<Object> temp = new ArrayList<Object>(); String hqlP = "FROM Personal P WHERE P.user = :usuario and P.pass = :password ";//:=login String hqlF = "FROM Familia F WHERE F.user = :usuario and F.pass = :password "; String hqlE = "FROM Entidad R WHERE R.user = :usuario and R.pass = :password "; Query queryP = session.createQuery(hqlP); queryP.setString("usuario", user); queryP.setString("password", pass); Object queryResultP = queryP.uniqueResult(); Query queryF = session.createQuery(hqlF); queryF.setString("usuario", user); queryF.setString("password", pass); Object queryResultF = queryF.uniqueResult(); Query queryE = session.createQuery(hqlE); queryE.setString("usuario", user); queryE.setString("password", pass); Object queryResultE = queryE.uniqueResult(); if (queryResultP != null) { personal = (Personal) queryResultP; Hibernate.initialize(personal.getUnidad()); temp.add("personal"); temp.add(personal); return temp; } else if (queryResultF != null) { familia = (Familia) queryResultF; Hibernate.initialize(familia.getInfoFamilias()); Hibernate.initialize(familia.getExpedienteFamilias()); Hibernate.initialize(familia.getFormularioSesions()); Hibernate.initialize(familia.getFichaSolicitudAdopcions()); Hibernate.initialize(familia.getPostAdopcions()); for (Iterator iter = familia.getInfoFamilias().iterator(); iter.hasNext();) { InfoFamilia ifa = (InfoFamilia) iter.next(); Hibernate.initialize(ifa.getAdoptantes()); Hibernate.initialize(ifa.getHijoActs()); Hibernate.initialize(ifa.getResidenteActs()); } for (Iterator iter2 = familia.getFichaSolicitudAdopcions().iterator(); iter2.hasNext();) { FichaSolicitudAdopcion ficha = (FichaSolicitudAdopcion) iter2.next(); Hibernate.initialize(ficha.getSolicitantes()); Hibernate.initialize(ficha.getHijos()); Hibernate.initialize(ficha.getResidentes()); } temp.add("familia"); temp.add(familia); return temp; } else if (queryResultE != null) { entidad = (Entidad) queryResultE; Hibernate.initialize(entidad.getAutoridads()); Hibernate.initialize(entidad.getOrganismos()); for (Iterator iter = entidad.getOrganismos().iterator(); iter.hasNext();) { Organismo org = (Organismo) iter.next(); Hibernate.initialize(org.getRepresentantes()); } if (entidad.getAutoridads().isEmpty()) { temp.add("representante"); } else { temp.add("autoridad"); } temp.add(entidad); return temp; } else { temp.add("none"); return temp; } }
From source file:io.apicurio.hub.core.editing.EditingSessionManager.java
/** * @see io.apicurio.hub.core.editing.IEditingSessionManager#createSessionUuid(java.lang.String, java.lang.String, java.lang.String, long) *///w w w . j a v a 2 s .c o m @Override public String createSessionUuid(String designId, String user, String secret, long contentVersion) throws ServerError { try { UUID uuid = UUID.randomUUID(); String hash = DigestUtils.sha512Hex(SALT + user + secret); long expiresOn = System.currentTimeMillis() + EXPIRATION_OFFSET; this.storage.createEditingSessionUuid(uuid.toString(), designId, user, hash, contentVersion, expiresOn); return uuid.toString(); } catch (StorageException e) { throw new ServerError(e); } }
From source file:com.qycloud.oatos.license.utils.LicenseUtil.java
private String sha(License license) { StringBuilder sb = new StringBuilder(); sb.append(strs[0]).append(license.getLicenseType()); sb.append(strs[1]).append(license.getLicenseVersion()); sb.append(strs[2]).append(license.getProductVersion()); sb.append(strs[3]).append(license.getLicenseTo()); sb.append(strs[4]).append(license.getKey()).append(license.getKey2()); sb.append(strs[5]).append(license.getMaxUser()); sb.append(strs[6]).append(license.getExpiry()); sb.append(strs[7]).append(license.getLicenseBy()); sb.append(strs[8]).append(license.getEmail()); sb.append(strs[9]).append(license.getTel()); String sha = DigestUtils.sha512Hex(sb.toString()); return sha;/*from ww w .ja v a 2 s . c o m*/ }
From source file:net.mohatu.bloocoin.miner.MinerClass.java
public void mine() throws NoSuchAlgorithmException { String currentString;/* ww w . ja v a 2s .co m*/ //String testString = "dx3NAa"; //dx3NAa257363 while (MainView.getStatus()) { String startString = randomString(); String hash = ""; MainView.updateStatusText("Starting: " + startString); for (int counter = 0; counter <= 100000000; counter++) { MainView.updateCounter(); currentString = startString + counter; hash = DigestUtils.sha512Hex(currentString); if (hash.startsWith(difficulty)) { MainView.updateStatusText("Success: " + currentString); Thread sub = new Thread(new SubmitterClass(hash, currentString)); sub.start(); MainView.updateSolved(currentString); try { PrintWriter out = new PrintWriter(new BufferedWriter( new FileWriter(System.getProperty("user.dir") + "/BLC_Solved.txt", true))); out.println(currentString); out.close(); } catch (IOException e) { // Error System.out.println("Could not save to BLC_Solved.txt, check permissions."); } } if (!MainView.getStatus()) { counter = 100000000; System.out.println("STOPPING"); } } } }
From source file:com.floragunn.searchguard.authentication.backend.simple.SettingsBasedAuthenticationBackend.java
@Override public User authenticate(final com.floragunn.searchguard.authentication.AuthCredentials authCreds) throws AuthException { final String user = authCreds.getUsername(); final char[] password = authCreds.getPassword(); authCreds.clear();// w ww .j a v a 2s . c o m String pass = settings.get(ConfigConstants.SEARCHGUARD_AUTHENTICATION_SETTINGSDB_USER + user, null); String digest = settings.get(ConfigConstants.SEARCHGUARD_AUTHENTICATION_SETTINGSDB_DIGEST, null); if (digest != null) { digest = digest.toLowerCase(); switch (digest) { case "sha": case "sha1": pass = DigestUtils.sha1Hex(pass); break; case "sha256": pass = DigestUtils.sha256Hex(pass); break; case "sha384": pass = DigestUtils.sha384Hex(pass); break; case "sha512": pass = DigestUtils.sha512Hex(pass); break; default: pass = DigestUtils.md5Hex(pass); break; } } if (pass != null && Arrays.equals(pass.toCharArray(), password)) { return new User(user); } throw new AuthException("No user " + user + " or wrong password (digest: " + (digest == null ? "plain/none" : digest) + ")"); }
From source file:fr.cnrs.sharp.test.GenProvenanceForFile.java
@Test public void hello() throws FileNotFoundException, IOException { StopWatch sw = new StopWatch(); sw.start();//from w w w . j av a2 s . c o m Path p = Paths.get("/Users/gaignard-a/Desktop/access.log-20150818"); String label = p.getFileName().toString(); System.out.println(); FileInputStream fis = new FileInputStream(p.toFile()); String sha512 = DigestUtils.sha512Hex(fis); System.out.println(""); System.out.println(sha512); System.out.println("SHA512 calculated in " + sw.getTime() + " ms."); StringBuffer sb = new StringBuffer(); sb.append("@base <http://fr.symetric> .\n" + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" + "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n" + "@prefix sioc: <http://rdfs.org/sioc/ns#> .\n" + "@prefix prov: <http://www.w3.org/ns/prov#> .\n" + "@prefix sym: <http://fr.symetric/vocab#> .\n" + "@prefix dcterms: <http://purl.org/dc/terms/> .\n" + "@prefix tavernaprov: <http://ns.taverna.org.uk/2012/tavernaprov/> .\n" + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"); sb.append("<#" + UUID.randomUUID().toString() + ">\n" + "\t a prov:Entity ;\n"); sb.append("\t rdfs:label \"" + label + "\"^^xsd:String ;\n"); sb.append("\t tavernaprov:sha512 \"" + sha512 + "\"^^xsd:String ."); System.out.println(""); System.out.println(""); System.out.println(sb.toString()); fis.close(); }
From source file:io.apiman.gateway.engine.policies.auth.JDBCIdentityValidator.java
/** * @see io.apiman.gateway.engine.policies.auth.IIdentityValidator#validate(java.lang.String, java.lang.String, io.apiman.gateway.engine.beans.ServiceRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.async.IAsyncHandler) *///from w w w . j a v a2s . c o m @Override public void validate(String username, String password, ServiceRequest request, IPolicyContext context, JDBCIdentitySource config, IAsyncResultHandler<Boolean> handler) { DataSource ds = lookupDatasource(config); String sqlPwd = password; switch (config.getHashAlgorithm()) { case MD5: sqlPwd = DigestUtils.md5Hex(password); break; case SHA1: sqlPwd = DigestUtils.shaHex(password); break; case SHA256: sqlPwd = DigestUtils.sha256Hex(password); break; case SHA384: sqlPwd = DigestUtils.sha384Hex(password); break; case SHA512: sqlPwd = DigestUtils.sha512Hex(password); break; case None: default: break; } String query = config.getQuery(); Connection conn = null; boolean validated = false; try { conn = ds.getConnection(); conn.setReadOnly(true); PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, username); statement.setString(2, sqlPwd); ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { validated = true; } resultSet.close(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { } } } handler.handle(AsyncResultImpl.create(validated)); }
From source file:net.mohatu.bloocoin.miner.SubmitListClass.java
private void submit() { for (int i = 0; i < solved.size(); i++) { try {/*www . ja v a2s.c o m*/ Socket sock = new Socket(this.url, this.port); String result = new String(); DataInputStream is = new DataInputStream(sock.getInputStream()); DataOutputStream os = null; BufferedReader in = new BufferedReader(new InputStreamReader(is)); solution = solved.get(i); hash = DigestUtils.sha512Hex(solution); String command = "{\"cmd\":\"check" + "\",\"winning_string\":\"" + solution + "\",\"winning_hash\":\"" + hash + "\",\"addr\":\"" + MainView.getAddr() + "\"}"; os = new DataOutputStream(sock.getOutputStream()); os.write(command.getBytes()); String inputLine; while ((inputLine = in.readLine()) != null) { result += inputLine; } if (result.contains("\"success\": true")) { System.out.println("Result: Submitted"); MainView.updateStatusText(solution + " submitted"); Thread gc = new Thread(new CoinClass()); gc.start(); } else if (result.contains("\"success\": false")) { System.out.println("Result: Failed"); MainView.updateStatusText("Submission of " + solution + " failed, already exists!"); } is.close(); os.close(); os.flush(); sock.close(); } catch (UnknownHostException e) { MainView.updateStatusText("Submission of " + solution + " failed, connection failed!"); } catch (IOException e) { MainView.updateStatusText("Submission of " + solution + " failed, connection failed!"); } } Thread gc = new Thread(new CoinClass()); gc.start(); }