List of usage examples for org.apache.commons.codec.binary Hex encodeHex
public static char[] encodeHex(byte[] data)
From source file:com.lightboxtechnologies.spectrum.ExtractMapper.java
protected Map<String, Object> process_extent_large(FSDataInputStream file, FileSystem fs, Path outPath, Map<String, ?> map, Context context) throws IOException { context.getCounter(FileTypes.BIG).increment(1); final Map<String, Object> rec = new HashMap<String, Object>(); OutputStream fout = null;/*from ww w . j a va 2 s . c om*/ try { fout = fs.create(outPath, true); hashAndExtract(rec, fout, file, map, context); } finally { IOUtils.closeQuietly(fout); } final String hash = new String(Hex.encodeHex((byte[]) rec.get("md5"))); final Path subDir = new Path("/texaspete/ev", hashFolder(hash)), hashPath = new Path(subDir, hash); fs.mkdirs(subDir); if (fs.exists(hashPath)) { context.getCounter(FileTypes.BIG_DUPES).increment(1); } else if (!fs.rename(outPath, hashPath)) { LOG.warn("Could not rename " + outPath + " to " + hashPath); context.getCounter(FileTypes.PROBLEMS).increment(1); } final StreamProxy content = new FileProxy(hashPath.toString()); rec.put("Content", content); return rec; }
From source file:com.qut.middleware.spep.authn.bindings.impl.ArtifactProcessorImpl.java
public Element execute(Element artifactRequest) throws AuthenticationException { ArtifactResolve artifactResolve = null; try {//from w ww . j a va2 s . co m this.logger.debug("Going to unmarshal ArtifactResolve document"); artifactResolve = this.artifactResolveUnmarshaller.unMarshallSigned(artifactRequest); String requestIssuer = artifactResolve.getIssuer().getValue(); String artifactToken = artifactResolve.getArtifact(); this.logger.info( "Unmarshalled ArtifactResolve document from issuer {} - requested artifact token is {}", new Object[] { requestIssuer, artifactToken }); Artifact artifact = new Artifact(artifactToken); byte[] sourceID = artifact.getSourceID(); boolean validSourceID = (sourceID.length == this.sourceID.length); if (validSourceID) { for (int i = 0; i < sourceID.length; ++i) { // Compare each byte in sequence if (sourceID[i] != this.sourceID[i]) { validSourceID = false; break; } } } if (!validSourceID) { // Convert source IDs to hex for logging. String sourceIDString = new String(Hex.encodeHex(sourceID)); String expectedSourceIDString = new String(Hex.encodeHex(this.sourceID)); String time = String.valueOf(System.currentTimeMillis()); this.logger.error("{} Source ID for artifact token was invalid. Was {} but should have been {}", new Object[] { time, sourceIDString, expectedSourceIDString }); return this.errorResponse(artifactResolve, StatusCodeConstants.requester, time + " Source ID for artifact token was invalid. Unable to respond"); } // Resolve the artifact from the underlying data source. this.resolveArtifact(artifact); String audience = artifact.getAudience(); Element document = artifact.getDocument(); if (!requestIssuer.equals(audience) || document == null) { String time = String.valueOf(System.currentTimeMillis()); this.logger.error( "{} Audience entity ID for artifact token was invalid. Will respond with no document content. Request issuer was {} but document audience was {}", new Object[] { time, requestIssuer, audience }); return this.statusResponse(artifactResolve, StatusCodeConstants.success, time + " The artifact request was successful but no artifact document to respond with.", null); } return this.statusResponse(artifactResolve, StatusCodeConstants.success, "The artifact request was successful.", document); } catch (SignatureValueException e) { artifactResolve = (ArtifactResolve) e.getJAXBObject(); String issuer; if (artifactResolve != null) { issuer = artifactResolve.getIssuer().getValue(); } else { issuer = "unknown issuer"; } String time = String.valueOf(System.currentTimeMillis()); this.logger.error( "{} Signature validation failed on ArtifactResolve request. Generating error response. Request issuer was {}. Error was: {}", new Object[] { time, issuer, e.getMessage() }); return this.errorResponse(artifactResolve, StatusCodeConstants.requester, time + "Signature validation failed on ArtifactResolve request. Unwilling to respond."); } catch (ReferenceValueException e) { artifactResolve = (ArtifactResolve) e.getJAXBObject(); String issuer; if (artifactResolve != null) { issuer = artifactResolve.getIssuer().getValue(); } else { issuer = "unknown issuer"; } String time = String.valueOf(System.currentTimeMillis()); this.logger.error( "{} Reference value failure on ArtifactResolve request. Generating error response. Request issuer was {}. Error was: {}", new Object[] { time, issuer, e.getMessage() }); return this.errorResponse(artifactResolve, StatusCodeConstants.requester, time + " Reference value failure on ArtifactResolve request. Unwilling to respond."); } catch (UnmarshallerException e) { artifactResolve = (ArtifactResolve) e.getJAXBObject(); String issuer; if (artifactResolve != null) { issuer = artifactResolve.getIssuer().getValue(); } else { issuer = "unknown issuer"; } String time = String.valueOf(System.currentTimeMillis()); this.logger.error( "{} Unmarshalling failed on ArtifactResolve request. Generating error response. Request issuer was {}. Error was: {}", new Object[] { time, issuer, e.getMessage() }); return this.errorResponse(artifactResolve, StatusCodeConstants.requester, time + " Unmarshalling failed on ArtifactResolve request. Unwilling to respond."); } }
From source file:com.qut.middleware.esoe.sso.plugins.artifact.impl.ArtifactProcessorImpl.java
public Element execute(Element artifactRequest) { ArtifactResolve artifactResolve = null; try {// w ww . j ava 2 s. c o m this.logger.debug("Going to unmarshal ArtifactResolve document"); artifactResolve = this.artifactResolveUnmarshaller.unMarshallSigned(artifactRequest); String requestIssuer = artifactResolve.getIssuer().getValue(); String artifactToken = artifactResolve.getArtifact(); this.logger.info( "Unmarshalled ArtifactResolve document from issuer {} - requested artifact token is {}", new Object[] { requestIssuer, artifactToken }); Artifact artifact = new Artifact(artifactToken); byte[] sourceID = artifact.getSourceID(); boolean validSourceID = (sourceID.length == this.sourceID.length); if (validSourceID) { for (int i = 0; i < sourceID.length; ++i) { // Compare each byte in sequence if (sourceID[i] != this.sourceID[i]) { validSourceID = false; break; } } } if (!validSourceID) { // Convert source IDs to hex for logging. String sourceIDString = new String(Hex.encodeHex(sourceID)); String expectedSourceIDString = new String(Hex.encodeHex(this.sourceID)); String time = String.valueOf(System.currentTimeMillis()); this.logger.error("{} Source ID for artifact token was invalid. Was {} but should have been {}", new Object[] { time, sourceIDString, expectedSourceIDString }); return this.errorResponse(artifactResolve, StatusCodeConstants.requester, time + " Source ID for artifact token was invalid. Unable to respond"); } // Resolve the artifact from the underlying data source. this.artifactDao.resolveArtifact(artifact); String audience = artifact.getAudience(); byte[] document = artifact.getDocument(); if (!requestIssuer.equals(audience) || document == null) { String time = String.valueOf(System.currentTimeMillis()); this.logger.error( "{} Audience entity ID for artifact token was invalid. Will respond with no document content. Request issuer was {} but document audience was {}", new Object[] { time, requestIssuer, audience }); return this.statusResponse(artifactResolve, StatusCodeConstants.success, time + " The artifact request was successful but no artifact document to respond with.", null); } Document artifactDocument = this.artifactResolveUnmarshaller.generateDocument(document, false); return this.statusResponse(artifactResolve, StatusCodeConstants.success, "The artifact request was successful.", artifactDocument.getDocumentElement()); } catch (SignatureValueException e) { artifactResolve = (ArtifactResolve) e.getJAXBObject(); String issuer; if (artifactResolve != null) { issuer = artifactResolve.getIssuer().getValue(); } else { issuer = "unknown issuer"; } String time = String.valueOf(System.currentTimeMillis()); this.logger.error( "{} Signature validation failed on ArtifactResolve request. Generating error response. Request issuer was {}. Error was: {}", new Object[] { time, issuer, e.getMessage() }); return this.errorResponse(artifactResolve, StatusCodeConstants.requester, time + "Signature validation failed on ArtifactResolve request. Unwilling to respond."); } catch (ReferenceValueException e) { artifactResolve = (ArtifactResolve) e.getJAXBObject(); String issuer; if (artifactResolve != null) { issuer = artifactResolve.getIssuer().getValue(); } else { issuer = "unknown issuer"; } String time = String.valueOf(System.currentTimeMillis()); this.logger.error( "{} Reference value failure on ArtifactResolve request. Generating error response. Request issuer was {}. Error was: {}", new Object[] { time, issuer, e.getMessage() }); return this.errorResponse(artifactResolve, StatusCodeConstants.requester, time + " Reference value failure on ArtifactResolve request. Unwilling to respond."); } catch (UnmarshallerException e) { artifactResolve = (ArtifactResolve) e.getJAXBObject(); String issuer; if (artifactResolve != null) { issuer = artifactResolve.getIssuer().getValue(); } else { issuer = "unknown issuer"; } String time = String.valueOf(System.currentTimeMillis()); this.logger.error( "{} Unmarshalling failed on ArtifactResolve request. Generating error response. Request issuer was {}. Error was: {}", new Object[] { time, issuer, e.getMessage() }); return this.errorResponse(artifactResolve, StatusCodeConstants.requester, time + " Unmarshalling failed on ArtifactResolve request. Unwilling to respond."); } catch (ArtifactBindingException e) { String issuer; if (artifactResolve != null) { issuer = artifactResolve.getIssuer().getValue(); } else { issuer = "unknown issuer"; } String time = String.valueOf(System.currentTimeMillis()); this.logger.error( "{} Artifact binding failed to process the request. Generating error response. Request issuer was {}. Error was: {}", new Object[] { time, issuer, e.getMessage() }); return this.errorResponse(artifactResolve, StatusCodeConstants.requester, time + " Artifact binding failed to process the request. Unwilling to respond."); } }
From source file:com.dtolabs.rundeck.core.resources.URLResourceModelSource.java
private String hashURL(final String url) { try {/*from w w w .ja v a 2 s . c o m*/ MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.reset(); digest.update(url.getBytes(Charset.forName("UTF-8"))); return new String(Hex.encodeHex(digest.digest())); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return Integer.toString(url.hashCode()); }
From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java
/** * Calculates the MD5 digest and returns the value as a 32 character hex string. * * @param data/*from w ww. j a v a2 s . c o m*/ * Data to digest * @return MD5 digest as a hex string */ public static String md5Hex(final String data) { return new String(Hex.encodeHex(md5(data))); }
From source file:davmail.util.StringUtil.java
/** * Convert base64 value to hex.// ww w .j a va 2 s .c om * * @param value base64 value * @return hex value */ public static String base64ToHex(String value) { String hexValue = null; if (value != null) { hexValue = new String(Hex.encodeHex(Base64.decodeBase64(value.getBytes()))); } return hexValue; }
From source file:com.moz.fiji.schema.util.TestJsonEntityIdParser.java
@Test public void testShouldWorkWithRKF2FormattedLayout() throws Exception { final TableLayoutDesc desc = FijiTableLayouts .getLayout(FijiTableLayouts.HASH_PREFIXED_FORMATTED_MULTI_COMPONENT); final FijiTableLayout layout = FijiTableLayout.newLayout(desc); // Construct complex entity id. final String eidString = String.format("[%s,%s,%s,%d,%d]", JSONObject.quote(UNUSUAL_STRING_EID), JSONObject.quote(UNUSUAL_STRING_EID), JSONObject.quote(UNUSUAL_STRING_EID), Integer.MIN_VALUE, Long.MAX_VALUE);/* w ww . j av a 2s . c o m*/ final EntityId originalEid = ToolUtils.createEntityIdFromUserInputs(eidString, layout); final JsonEntityIdParser restEid1 = JsonEntityIdParser.create(originalEid, layout); final JsonEntityIdParser restEid2 = JsonEntityIdParser.create(eidString, layout); final JsonEntityIdParser restEid3 = JsonEntityIdParser.create( String.format("hbase_hex=%s", new String(Hex.encodeHex((originalEid.getHBaseRowKey())))), layout); final JsonEntityIdParser restEid4 = JsonEntityIdParser .create(String.format("hbase=%s", Bytes.toStringBinary(originalEid.getHBaseRowKey())), layout); final EntityId toolUtilsEid = ToolUtils.createEntityIdFromUserInputs(eidString, layout); // Resolved entity id should match origin entity id. assertEquals(originalEid, restEid1.getEntityId()); assertEquals(originalEid, restEid2.getEntityId()); assertEquals(originalEid, restEid3.getEntityId()); assertEquals(originalEid, restEid4.getEntityId()); assertEquals(toolUtilsEid, restEid4.getEntityId()); }
From source file:com.mdt.rtm.Invoker.java
final String calcApiSig(Param... params) throws ServiceInternalException { try {/*w ww. j a v a 2 s .c om*/ digest.reset(); digest.update(applicationInfo.getSharedSecret().getBytes(ENC)); List<Param> sorted = Arrays.asList(params); Collections.sort(sorted); for (Param param : sorted) { digest.update(param.getName().getBytes(ENC)); digest.update(param.getValue().getBytes(ENC)); } return new String(Hex.encodeHex(digest.digest())); // return new String(digest.digest(), ENC); } catch (UnsupportedEncodingException e) { throw new ServiceInternalException("cannot hahdle properly the encoding", e); } }
From source file:android.database.DatabaseUtils.java
/** * return the collation key in hex format * @param name// w w w.ja v a 2 s.c om * @return the collation key in hex format */ public static String getHexCollationKey(String name) { byte[] arr = getCollationKeyInBytes(name); char[] keys = Hex.encodeHex(arr); return new String(keys, 0, getKeyLen(arr) * 2); }
From source file:com.francetelecom.admindm.com.UDPConnectionRequest.java
/** * <p>/* www . j av a2 s. co m*/ * Authenticate the UDPConnectionRequest. * </p> * <p> * The following actions are performed: * <ul> * <li>check if the RequestURI SIG attribute is equal to the computed * signature.</li> * </ul> * </p> * * @return true if authentication phase succeed else false. */ private boolean authenticate() { Log.debug("enter authenticate"); try { Parameter connectionRequestPasswordParameter = parameterData .createOrRetrieveParameter(parameterData.getRoot() + CONNECTION_REQUEST_PASSWORD); String password = (String) connectionRequestPasswordParameter.getValue(); Log.debug("password = " + password); // create a secret key SecretKeySpec signinKey = new SecretKeySpec(password.getBytes(), HMAC_SHA1_ALGORITHM); // get a Mac instance Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM); mac.init(signinKey); // compute value String text = requestURI.getAttribute(RequestURIParser.TS) + requestURI.getAttribute(RequestURIParser.ID) + requestURI.getAttribute(RequestURIParser.UN) + requestURI.getAttribute(RequestURIParser.CN); Log.debug("text = " + text); // computed signature (ensure lower case character) byte[] signature = mac.doFinal(text.getBytes()); String computedSignature = new String(Hex.encodeHex(signature)).toLowerCase(); Log.debug("computed signature = " + computedSignature); // get the signature from the message String receivedSignature = requestURI.getAttribute(RequestURIParser.SIG); // ensure lower case receivedSignature = receivedSignature.toLowerCase(); if (receivedSignature == null) { Log.error("signature key null"); return false; } else { if (!receivedSignature.equals(computedSignature)) { Log.error("invalid signature"); return false; } } } catch (Fault e) { Log.error("unable to get the " + "IGD.ManagementServer.ConnectionRequestPassword"); return false; } catch (NoSuchAlgorithmException e) { Log.error("Unable to get the HMAC-SHA1 algo"); return false; } catch (InvalidKeyException e) { Log.error("Unable to sign the key"); return false; } Log.info("UDP Connection Request authenticated"); return true; }