List of usage examples for org.apache.commons.codec.digest DigestUtils sha256Hex
public static String sha256Hex(String data)
From source file:com.formkiq.core.dao.FolderDaoImplTest.java
/** * testFindFormsByForm02()./*from www. jav a 2 s . c o m*/ * @throws IOException IOException */ @Transactional @Test public void testFindFormsByForm02() throws IOException { // given FolderFormsSearchCriteria criteria = new FolderFormsSearchCriteria(); criteria.setOrderby(FormOrderByField.NAME); criteria.setSorter(SortDirection.ASC); criteria.setStatus(Arrays.asList(FolderFormStatus.ACTIVE)); User user = createUser("AAA", UserRole.ROLE_USER); final int secondsInMinute = 60; String updatedDate = "2016-03-17T10:26:"; String token = null; UUID formId = UUID.randomUUID(); UUID folder = UUID.randomUUID(); String sha256hash = DigestUtils.sha256Hex(folder + " " + formId); final int max = 10; final int formCount = 13; Asset asset = createAsset("test"); for (int i = 0; i < formCount; i++) { FolderForm form = new FolderForm(); form.setType(ClientFormType.FORM); form.setFolderid(folder); form.setParentUUID(formId); form.setUUID(UUID.randomUUID()); form.setInsertedDate(new Date()); form.setUpdatedDate(new Date()); form.setStatus(FolderFormStatus.ACTIVE); form.setSha1hash("uuid" + String.format("%02d", Integer.valueOf(i))); form.setAssetid(asset.getAssetId()); form.setData( "{\"name\":\"name" + String.format("%02d", Integer.valueOf(i)) + "\"," + "\"updated_date\":\"" + updatedDate + String.format("%02d", Integer.valueOf(secondsInMinute - i)) + "-0500" + "\"," + "\"uuid\":\"uuid" + String.format("%02d", Integer.valueOf(i)) + "\"}"); this.folderDao.saveForm(user, form, sha256hash); } getEntityManager().flush(); // when FolderFormsListDTO result = this.folderDao.findForms(folder.toString(), formId.toString(), criteria, token); // then assertEquals("MTA6MTA=", result.getNexttoken()); assertNull(result.getPrevtoken()); int i = 0; List<FormDTO> forms = result.getForms(); assertEquals(max, forms.size()); assertEquals("uuid00", forms.get(i++).getSha1hash()); assertEquals("uuid01", forms.get(i++).getSha1hash()); assertEquals("uuid02", forms.get(i++).getSha1hash()); assertEquals("uuid03", forms.get(i++).getSha1hash()); assertEquals("uuid04", forms.get(i++).getSha1hash()); assertEquals("uuid05", forms.get(i++).getSha1hash()); assertEquals("uuid06", forms.get(i++).getSha1hash()); assertEquals("uuid07", forms.get(i++).getSha1hash()); assertEquals("uuid08", forms.get(i++).getSha1hash()); assertEquals("uuid09", forms.get(i++).getSha1hash()); // when result = this.folderDao.findForms(folder.toString(), formId.toString(), criteria, result.getNexttoken()); // then assertNull(result.getNexttoken()); assertEquals("MDoxMA==", result.getPrevtoken()); final int max1 = 3; i = 0; forms = result.getForms(); assertEquals(max1, forms.size()); assertEquals("uuid10", forms.get(i++).getSha1hash()); assertEquals("uuid11", forms.get(i++).getSha1hash()); assertEquals("uuid12", forms.get(i++).getSha1hash()); // when result = this.folderDao.findForms(folder.toString(), formId.toString(), criteria, result.getPrevtoken()); // then i = 0; forms = result.getForms(); assertEquals("MTA6MTA=", result.getNexttoken()); assertNull(result.getPrevtoken()); assertEquals(max, forms.size()); assertEquals("uuid00", forms.get(i++).getSha1hash()); assertEquals("uuid01", forms.get(i++).getSha1hash()); assertEquals("uuid02", forms.get(i++).getSha1hash()); assertEquals("uuid03", forms.get(i++).getSha1hash()); assertEquals("uuid04", forms.get(i++).getSha1hash()); assertEquals("uuid05", forms.get(i++).getSha1hash()); assertEquals("uuid06", forms.get(i++).getSha1hash()); assertEquals("uuid07", forms.get(i++).getSha1hash()); assertEquals("uuid08", forms.get(i++).getSha1hash()); assertEquals("uuid09", forms.get(i++).getSha1hash()); }
From source file:eu.cloud4soa.soa.ApplicationDeployment.java
private String getFileDigest(File file) throws SOAException { InputStream fileStream;//from ww w. j a va 2s . co m String digest; try { fileStream = new FileInputStream(file); digest = DigestUtils.sha256Hex(fileStream); } catch (IOException ie) { throw new SOAException(Response.Status.BAD_REQUEST, "Failed to process attachments. Reason : " + ie.getMessage()); } return digest; }
From source file:com.formkiq.core.dao.FolderDaoImplTest.java
/** * testFindWorkflows01().//from w w w . j a v a 2 s. c om * @throws IOException IOException */ @Transactional @Test public void testFindWorkflows01() throws IOException { // given FolderFormsSearchCriteria criteria = new FolderFormsSearchCriteria(); criteria.setOrderby(FormOrderByField.NAME); criteria.setSorter(SortDirection.ASC); criteria.setStatus(Arrays.asList(FolderFormStatus.ACTIVE)); User user = createUser("AAA", UserRole.ROLE_USER); String token = null; UUID folder = UUID.randomUUID(); UUID uuid = UUID.randomUUID(); UUID parentuuid = UUID.randomUUID(); String sha256hash = DigestUtils.sha256Hex(folder + " " + uuid); String json = "{\"uuid\":\"B64EA338-CC4D-464C-ACD4-3E3B34CCAE02\"," + "\"updated_date\":\"2016-03-17T10:26:56-0500\"," + "\"name\":\"test\"}"; createClientWorkflow(user, folder, parentuuid, uuid); FolderForm w = new FolderForm(); w.setType(ClientFormType.WORKFLOW); w.setFolderid(folder); w.setData(json); w.setSha1hash("BBB"); w.setUUID(uuid); w.setInsertedDate(new Date()); w.setUpdatedDate(new Date()); w.setAssetid(UUID.randomUUID()); w.setStatus(FolderFormStatus.ACTIVE); this.folderDao.saveForm(user, w, sha256hash); getEntityManager().flush(); // when FolderFormsListDTO result = this.folderDao.findForms(folder.toString(), null, criteria, token); // then assertEquals(1, result.getForms().size()); FormDTO dto = result.getForms().get(0); assertEquals("test", dto.getName()); assertEquals("BBB", dto.getSha1hash()); assertEquals("B64EA338-CC4D-464C-ACD4-3E3B34CCAE02", dto.getUUID()); }
From source file:com.formkiq.core.dao.FolderDaoImplTest.java
/** * testFindWorkflowsByParent01().//from w w w.j ava 2 s. c om * with parent * @throws IOException IOException */ @Transactional @Test public void testFindWorkflowsByParent01() throws IOException { // given FolderFormsSearchCriteria criteria = new FolderFormsSearchCriteria(); criteria.setOrderby(FormOrderByField.NAME); criteria.setSorter(SortDirection.ASC); criteria.setStatus(Arrays.asList(FolderFormStatus.ACTIVE)); User user = createUser("AAA", UserRole.ROLE_USER); String token = null; UUID folder = UUID.randomUUID(); UUID workflow = UUID.randomUUID(); UUID uuid = UUID.randomUUID(); String sha256hash = DigestUtils.sha256Hex(folder + " " + uuid); String json = "{\"uuid\":\"B64EA338-CC4D-464C-ACD4-3E3B34CCAE02\"," + "\"updated_date\":\"2016-03-17T10:26:56-0500\"," + "\"name\":\"test\"}"; FolderForm w = new FolderForm(); w.setType(ClientFormType.WORKFLOW); w.setFolderid(folder); w.setData(json); w.setSha1hash("BBB"); w.setUUID(uuid); w.setAssetid(UUID.randomUUID()); w.setParentUUID(workflow); w.setInsertedDate(new Date()); w.setUpdatedDate(new Date()); w.setStatus(FolderFormStatus.ACTIVE); this.folderDao.saveForm(user, w, sha256hash); getEntityManager().flush(); // when FolderFormsListDTO result = this.folderDao.findForms(folder.toString(), workflow.toString(), criteria, token); // then assertEquals(1, result.getForms().size()); FormDTO dto = result.getForms().get(0); assertEquals("test", dto.getName()); assertEquals("BBB", dto.getSha1hash()); assertEquals("B64EA338-CC4D-464C-ACD4-3E3B34CCAE02", dto.getUUID()); }
From source file:com.formkiq.core.dao.FolderDaoImplTest.java
/** * testFindWorkflowsByParent02().//from ww w . j ava 2s . c o m * with parent * @throws IOException IOException */ @Transactional @Test public void testFindWorkflowsByParent02() throws IOException { // given FolderFormsSearchCriteria criteria = new FolderFormsSearchCriteria(); criteria.setOrderby(FormOrderByField.NAME); criteria.setSorter(SortDirection.ASC); criteria.setStatus(Arrays.asList(FolderFormStatus.ACTIVE)); User user = createUser("AAA", UserRole.ROLE_USER); final int secondsInMinute = 60; String updatedDate = "2016-03-17T10:26:"; final int max = 10; final int workflowCount = 13; String token = null; UUID workflow = UUID.randomUUID(); String uuid = "zz"; UUID folder = UUID.randomUUID(); String sha256hash = DigestUtils.sha256Hex(folder + " " + uuid); for (int i = 0; i < workflowCount; i++) { FolderForm w = new FolderForm(); w.setType(ClientFormType.WORKFLOW); w.setFolderid(folder); w.setData("{\"name\":\"" + uuid + String.format("%02d", Integer.valueOf(i)) + "\"," + "\"updated_date\":\"" + updatedDate + String.format("%02d", Integer.valueOf(secondsInMinute - i)) + "-0500" + "\"," + "\"uuid\":\"" + uuid + String.format("%02d", Integer.valueOf(i)) + "\"}"); w.setSha1hash("zz" + String.format("%02d", Integer.valueOf(i))); w.setUUID(UUID.randomUUID()); w.setAssetid(UUID.randomUUID()); w.setInsertedDate(new Date()); w.setUpdatedDate(new Date()); w.setParentUUID(workflow); w.setStatus(FolderFormStatus.ACTIVE); this.folderDao.saveForm(user, w, sha256hash); } getEntityManager().flush(); // when FolderFormsListDTO result = this.folderDao.findForms(folder.toString(), workflow.toString(), criteria, token); // then assertEquals("MTA6MTA=", result.getNexttoken()); assertNull(result.getPrevtoken()); int i = 0; List<FormDTO> forms = result.getForms(); assertEquals(max, forms.size()); assertEquals("zz00", forms.get(i++).getSha1hash()); assertEquals("zz01", forms.get(i++).getSha1hash()); assertEquals("zz02", forms.get(i++).getSha1hash()); assertEquals("zz03", forms.get(i++).getSha1hash()); assertEquals("zz04", forms.get(i++).getSha1hash()); assertEquals("zz05", forms.get(i++).getSha1hash()); assertEquals("zz06", forms.get(i++).getSha1hash()); assertEquals("zz07", forms.get(i++).getSha1hash()); assertEquals("zz08", forms.get(i++).getSha1hash()); assertEquals("zz09", forms.get(i++).getSha1hash()); // when result = this.folderDao.findForms(folder.toString(), workflow.toString(), criteria, result.getNexttoken()); // then assertNull(result.getNexttoken()); assertEquals("MDoxMA==", result.getPrevtoken()); final int max1 = 3; i = 0; forms = result.getForms(); assertEquals(max1, forms.size()); assertEquals("zz10", forms.get(i++).getSha1hash()); assertEquals("zz11", forms.get(i++).getSha1hash()); assertEquals("zz12", forms.get(i++).getSha1hash()); // when result = this.folderDao.findForms(folder.toString(), workflow.toString(), criteria, result.getPrevtoken()); // then i = 0; forms = result.getForms(); assertEquals("MTA6MTA=", result.getNexttoken()); assertNull(result.getPrevtoken()); assertEquals(max, forms.size()); assertEquals("zz00", forms.get(i++).getSha1hash()); assertEquals("zz01", forms.get(i++).getSha1hash()); assertEquals("zz02", forms.get(i++).getSha1hash()); assertEquals("zz03", forms.get(i++).getSha1hash()); assertEquals("zz04", forms.get(i++).getSha1hash()); assertEquals("zz05", forms.get(i++).getSha1hash()); assertEquals("zz06", forms.get(i++).getSha1hash()); assertEquals("zz07", forms.get(i++).getSha1hash()); assertEquals("zz08", forms.get(i++).getSha1hash()); assertEquals("zz09", forms.get(i++).getSha1hash()); }
From source file:be.fedict.eid.tsl.TrustServiceList.java
public String getSha256Fingerprint() { String fingerprint = DigestUtils.sha256Hex(toByteArray()); return fingerprint; }
From source file:com.hotelbeds.distribution.hotel_api_sdk.HotelApiClient.java
private Headers getHeaders(AllowedMethod httpMethod) { Headers.Builder headersBuilder = new Headers.Builder(); headersBuilder.add(API_KEY_HEADER_NAME, apiKey); headersBuilder.add("User-Agent", "hotel-api-sdk-java, " + getClass().getPackage().getImplementationVersion()); // Hash the Api Key + Shared Secret + Current timestamp in seconds headersBuilder.add(SIGNATURE_HEADER_NAME, DigestUtils.sha256Hex(apiKey + sharedSecret + System.currentTimeMillis() / 1000)); switch (httpMethod) { case POST:/*from w w w .ja v a 2 s . co m*/ // case PUT: headersBuilder.add("Content-Type", APPLICATION_JSON_HEADER); case GET: case DELETE: headersBuilder.add("Accept", APPLICATION_JSON_HEADER); break; default: break; } return headersBuilder.build(); }
From source file:com.formkiq.core.dao.FolderDaoImplTest.java
/** * testHasFormChildren01().//ww w . jav a 2 s .c o m * has children */ @Transactional @Test public void testHasFormChildren01() { // given UUID uuid = UUID.randomUUID(); UUID folder = UUID.randomUUID(); String sha256hash = DigestUtils.sha256Hex(folder + " " + uuid); User user = createUser("AAA", UserRole.ROLE_USER); Asset asset = createAsset("test"); FolderForm form0 = new FolderForm(); form0.setType(ClientFormType.FORM); form0.setFolderid(folder); form0.setUUID(uuid); form0.setStatus(FolderFormStatus.ACTIVE); form0.setSha1hash("FFFF"); form0.setInsertedDate(new Date()); form0.setUpdatedDate(new Date()); form0.setAssetid(asset.getAssetId()); form0.setData(JSON); this.folderDao.saveForm(user, form0, sha256hash); FolderForm form1 = new FolderForm(); form1.setType(ClientFormType.FORM); form1.setFolderid(folder); form1.setParentUUID(uuid); form1.setUUID(UUID.randomUUID()); form1.setSha1hash("FFFF"); form1.setAssetid(asset.getAssetId()); form1.setData(JSON); form1.setInsertedDate(new Date()); form1.setUpdatedDate(new Date()); form1.setStatus(FolderFormStatus.ACTIVE); this.folderDao.saveForm(user, form1, sha256hash); getEntityManager().flush(); // when boolean result = this.folderDao.hasFormChildren(folder.toString(), uuid.toString()); // then assertTrue(result); }
From source file:com.formkiq.core.dao.FolderDaoImplTest.java
/** * testHasFormChildren02()./*w w w . j a v a 2s . co m*/ * has 0 children */ @Transactional @Test public void testHasFormChildren02() { // given UUID uuid = UUID.randomUUID(); UUID folder = UUID.randomUUID(); String sha256hash = DigestUtils.sha256Hex(folder + " " + uuid); User user = createUser("AAA", UserRole.ROLE_USER); Asset asset = createAsset("test"); FolderForm form0 = new FolderForm(); form0.setType(ClientFormType.FORM); form0.setFolderid(folder); form0.setUUID(uuid); form0.setSha1hash("FFFF"); form0.setInsertedDate(new Date()); form0.setUpdatedDate(new Date()); form0.setAssetid(asset.getAssetId()); form0.setData(JSON); form0.setStatus(FolderFormStatus.ACTIVE); this.folderDao.saveForm(user, form0, sha256hash); getEntityManager().flush(); // when boolean result = this.folderDao.hasFormChildren(folder.toString(), uuid.toString()); // then assertFalse(result); }
From source file:eu.cloud4soa.soa.jaxrs.test.Initializer.java
public void deployApplication() throws FileNotFoundException { final String RS_URI = BASE_URI + "ApplicationDeploymentRS/deployApplication"; WebClient client = WebClient.create(RS_URI); client.type("multipart/mixed").accept(MediaType.TEXT_PLAIN); URL fileURL = this.getClass().getClassLoader().getResource("SimpleWar.war"); if (fileURL == null) { throw new FileNotFoundException("SimpleWar.war"); }/*from ww w . j a va 2s . c om*/ ByteArrayOutputStream bas = new ByteArrayOutputStream(); File file = new File(fileURL.getPath()); file.length(); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream(bis); //Calculate digest from InputStream // InputStream tempIs = new FileInputStream(file); String tempFileDigest = null; try { FileInputStream tempFis = new FileInputStream(file); tempFileDigest = DigestUtils.sha256Hex(tempFis); } catch (IOException ex) { logger.error(ex.getMessage()); } JSONProvider jsonProvider = new JSONProvider(); jsonProvider.setSupportUnwrapped(false); jsonProvider.setSerializeAsArray(true); ProviderFactory.getSharedInstance().registerUserProvider(jsonProvider); // POST the request // Response response = applicationDeploymentRS.deployApplication(dis, applicationInstanceJsonObj, paaSInstanceJsonObj); List<Attachment> atts = new LinkedList<Attachment>(); atts.add(new Attachment("applicationInstanceUriId", "text/plain", applicationInstanceUriId)); atts.add(new Attachment("paaSInstanceUriId", "text/plain", paaSInstanceUriIds.get(selectedPaaS))); atts.add(new Attachment("publicKey", "text/plain", publicKey)); atts.add(new Attachment("secretKey", "text/plain", secretKey)); atts.add(new Attachment("applicationArchive", "application/octet-stream", dis)); Response response = client.post(new MultipartBody(atts)); if (Response.Status.fromStatusCode(response.getStatus()) == Response.Status.ACCEPTED) { try { System.out.println( "Response Status : " + IOUtils.readStringFromStream((InputStream) response.getEntity())); } catch (IOException ex) { logger.error(ex.getMessage()); } } try { fis.close(); bis.close(); dis.close(); } catch (IOException ex) { logger.error(ex.getMessage()); } }