javax.xml.bind.annotation.adapters.HexBinaryAdapter Java Examples

The following examples show how to use javax.xml.bind.annotation.adapters.HexBinaryAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PaymentUtils.java    From java-pay with Apache License 2.0 6 votes vote down vote up
/**
 * 生成 HMAC_SHA256
 *
 * @param content
 * @param api_key
 * @return
 * @throws Exception
 */
public static String HMAC_SHA256(String content, String api_key) {
    try {
        KeyGenerator generator = KeyGenerator.getInstance("HmacSHA256");
        SecretKey secretKey = generator.generateKey();
        byte[] key = secretKey.getEncoded();
        SecretKey secretKeySpec = new SecretKeySpec(api_key.getBytes(), "HmacSHA256");
        Mac mac = Mac.getInstance(secretKeySpec.getAlgorithm());
        mac.init(secretKeySpec);
        byte[] digest = mac.doFinal(content.getBytes());
        return new HexBinaryAdapter().marshal(digest).toLowerCase();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;

}
 
Example #2
Source File: Security.java    From NoraUi with GNU Affero General Public License v3.0 6 votes vote down vote up
public String createSha1(File file) throws TechnicalException {
    try (InputStream fis = new FileInputStream(file);) {
        MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
        int n = 0;
        byte[] buffer = new byte[8192];
        while (n != -1) {
            n = fis.read(buffer);
            if (n > 0) {
                sha1.update(buffer, 0, n);
            }
        }
        return new HexBinaryAdapter().marshal(sha1.digest());
    } catch (NoSuchAlgorithmException | IOException e) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_CHECKSUM_IO_EXCEPTION), e);
    }
}
 
Example #3
Source File: SignIn.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
public String encrpPass(String password){
    MessageDigest md5 = null;
    try {
        md5 = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return (new HexBinaryAdapter()).marshal(md5.digest(password.getBytes()));
}
 
Example #4
Source File: UniformRapidSuspensionCommandTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private void persistDomainWithHosts(HostResource... hosts) {
  ImmutableSet.Builder<VKey<HostResource>> hostRefs = new ImmutableSet.Builder<>();
  for (HostResource host : hosts) {
    hostRefs.add(host.createVKey());
  }
  persistResource(newDomainBase("evil.tld").asBuilder()
      .setNameservers(hostRefs.build())
      .setDsData(ImmutableSet.of(
          DelegationSignerData.create(1, 2, 3, new HexBinaryAdapter().unmarshal("dead")),
          DelegationSignerData.create(4, 5, 6, new HexBinaryAdapter().unmarshal("beef"))))
      .build());
}
 
Example #5
Source File: UniformRapidSuspensionCommand.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private ImmutableSortedSet<String> getExistingDsData(DomainBase domain) {
  ImmutableSortedSet.Builder<String> dsDataJsons = ImmutableSortedSet.naturalOrder();
  HexBinaryAdapter hexBinaryAdapter = new HexBinaryAdapter();
  for (DelegationSignerData dsData : domain.getDsData()) {
    dsDataJsons.add(JSONValue.toJSONString(ImmutableMap.of(
        "keyTag", dsData.getKeyTag(),
        "algorithm", dsData.getAlgorithm(),
        "digestType", dsData.getDigestType(),
        "digest", hexBinaryAdapter.marshal(dsData.getDigest()))));
  }
  return dsDataJsons.build();
}
 
Example #6
Source File: Config.java    From DBforBIX with GNU General Public License v3.0 5 votes vote down vote up
public static String calculateMD5Sum(String inStr) {
	MessageDigest hasher = null;
	try{
		hasher = java.security.MessageDigest.getInstance("MD5");
	}
	catch(NoSuchAlgorithmException e){
		LOG.error("Wrong hashing algorithm name provided while getting instance of MessageDigest: " + e.getLocalizedMessage());
	}
	return (new HexBinaryAdapter()).marshal(hasher.digest(inStr.getBytes()));
}
 
Example #7
Source File: AbstractRDFParser.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a {@link BNode} object for the specified identifier.
 */
@Deprecated
protected BNode createBNode(String nodeID) throws RDFParseException {
	// If we are preserving blank node ids then we do not prefix them to
	// make them globally unique
	if (preserveBNodeIDs()) {
		return valueFactory.createBNode(nodeID);
	} else {
		// Prefix the node ID with a unique UUID prefix to reduce
		// cross-document clashes
		// This is consistent as long as nextBNodePrefix is not modified
		// between parser runs

		String toAppend = nodeID;
		if (nodeID.length() > 32) {
			// we only hash the node ID if it is longer than the hash string
			// itself would be.
			byte[] chars = nodeID.getBytes(StandardCharsets.UTF_8);

			// we use an MD5 hash rather than the node ID itself to get a
			// fixed-length generated id, rather than
			// an ever-growing one (see SES-2171)
			toAppend = (new HexBinaryAdapter()).marshal(md5.digest(chars));
		}

		return valueFactory.createBNode("genid-" + nextBNodePrefix + toAppend);

	}
}
 
Example #8
Source File: AbstractRDFParser.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a {@link BNode} or Skolem {@link IRI} object for the specified identifier.
 */
protected Resource createNode(String nodeID) throws RDFParseException {
	// If we are preserving blank node ids then we do not prefix them to
	// make them globally unique
	if (preserveBNodeIDs()) {
		return valueFactory.createBNode(nodeID);
	} else {
		// Prefix the node ID with a unique UUID prefix to reduce
		// cross-document clashes
		// This is consistent as long as nextBNodePrefix is not modified
		// between parser runs

		String toAppend = nodeID;
		if (nodeID.length() > 32) {
			// we only hash the node ID if it is longer than the hash string
			// itself would be.
			byte[] chars = nodeID.getBytes(StandardCharsets.UTF_8);

			// we use an MD5 hash rather than the node ID itself to get a
			// fixed-length generated id, rather than
			// an ever-growing one (see SES-2171)
			toAppend = (new HexBinaryAdapter()).marshal(md5.digest(chars));
		}

		String origin = parserConfig.get(BasicParserSettings.SKOLEMIZE_ORIGIN);
		if (origin == null || origin.length() == 0) {
			return valueFactory.createBNode("genid-" + nextBNodePrefix + toAppend);
		} else {
			String path = "/.well-known/genid/" + nextBNodePrefix + toAppend;
			String iri = ParsedIRI.create(origin).resolve(path);
			return valueFactory.createIRI(iri);
		}
	}
}
 
Example #9
Source File: TightCouplingProcessor.java    From service-block-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Converts an arbitrary message into an MD5 hash and returns it as a UTF-8 encoded string
 *
 * @param message is the message to convert
 * @return a UTF-8 encoded string representation of the MD5 hash
 */
String getMd5Hash(String message) {
    String result;

    try {
        MessageDigest md5 = MessageDigest.getInstance(MD5);
        result = (new HexBinaryAdapter()).marshal(md5.digest(message.getBytes())).toLowerCase();
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Error converting message to MD5 hash", e);
    }

    return result;
}
 
Example #10
Source File: SignIn.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
public String encrpPass(String password){
    MessageDigest md5 = null;
    try {
        md5 = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return (new HexBinaryAdapter()).marshal(md5.digest(password.getBytes()));
}
 
Example #11
Source File: SignIn.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
public String encrpPass(String password){
    MessageDigest md5 = null;
    try {
        md5 = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return (new HexBinaryAdapter()).marshal(md5.digest(password.getBytes()));
}
 
Example #12
Source File: Util.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the unique ID.
 *
 * @param idstring
 *            the idstring
 * @return the unique ID
 */
public static String getUniqueID(String idstring) {
    try {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        return (new HexBinaryAdapter()).marshal(md5.digest(idstring.getBytes()));
    } catch (NoSuchAlgorithmException e) {
        LOGGER.error("Error in getUniqueID",e);
    }
    return "";
}
 
Example #13
Source File: Util.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the unique ID.
 *
 * @param idstring
 *            the idstring
 * @return the unique ID
 */
public static String getUniqueID(String idstring) {
    try {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        return (new HexBinaryAdapter()).marshal(md5.digest(idstring.getBytes()));
    } catch (NoSuchAlgorithmException e) {
        LOGGER.error("Error in getUniqueID",e);
    }
    return "";
}
 
Example #14
Source File: Util.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the unique ID.
 *
 * @param idstring
 *            the idstring
 * @return the unique ID
 */
public static String getUniqueID(String idstring) {
    try {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        return (new HexBinaryAdapter()).marshal(md5.digest(idstring.getBytes()));
    } catch (NoSuchAlgorithmException e) {
        LOGGER.error("Error in getUniqueID",e);
    }
    return "";
}
 
Example #15
Source File: PaymentUtils.java    From java-pay with Apache License 2.0 5 votes vote down vote up
/**
 * 生成md5摘要
 *
 * @param content
 * @return
 */
public static String MD5(String content) {
    try {
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
        messageDigest.update(content.getBytes(StandardCharsets.UTF_8));
        byte[] hashCode = messageDigest.digest();
        return new HexBinaryAdapter().marshal(hashCode).toLowerCase();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #16
Source File: MD5.java    From easy-sentinel with Apache License 2.0 5 votes vote down vote up
public static String encodeMd5(byte[] data) {
    // 初始化MessageDigest
    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    // 执行摘要信息
    byte[] digest = md.digest(data);
    // 将摘要信息转换为32位的十六进制字符串
    return new String(new HexBinaryAdapter().marshal(digest));
}
 
Example #17
Source File: ParameterProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void processXmlSchemaSimpleType(XmlSchemaSimpleType xmlSchema, JavaMethod method,
                                               MessagePartInfo part) {
    if (xmlSchema.getContent() instanceof XmlSchemaSimpleTypeList
        && (!part.isElement() || !method.isWrapperStyle())) {
        method.annotate(new XmlListAnotator(method.getInterface()));
    }
    if (Constants.XSD_HEXBIN.equals(xmlSchema.getQName())
        && (!part.isElement() || !method.isWrapperStyle())) {
        method.annotate(new XmlJavaTypeAdapterAnnotator(method.getInterface(), HexBinaryAdapter.class));
    }
}
 
Example #18
Source File: ParameterMapper.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void processXmlSchemaSimpleType(XmlSchemaSimpleType xmlSchema, JavaMethod jm,
                                               JavaParameter parameter, MessagePartInfo part) {
    if (xmlSchema.getContent() instanceof XmlSchemaSimpleTypeList
        && (!part.isElement() || !jm.isWrapperStyle())) {
        parameter.annotate(new XmlListAnotator(jm.getInterface()));
    }
    if (Constants.XSD_HEXBIN.equals(xmlSchema.getQName())
        && (!part.isElement() || !jm.isWrapperStyle())) {
        parameter.annotate(new XmlJavaTypeAdapterAnnotator(jm.getInterface(), HexBinaryAdapter.class));
    }
}
 
Example #19
Source File: MultipleDigestOutputStream.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getMessageDigestAsHexadecimalString (String algorithm)
{
   return (new HexBinaryAdapter()).marshal (
      getMessageDigest (algorithm).digest ());
}
 
Example #20
Source File: ConfigurerImplTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigureSimpleNoMatchingBean() {
    SimpleBean sb = new SimpleBean("unknown");

    BusApplicationContext ac =
        new BusApplicationContext("/org/apache/cxf/configuration/spring/test-beans.xml",
                                  false);

    ConfigurerImpl configurer = new ConfigurerImpl(ac);
    configurer.configureBean(sb);
    assertEquals("Unexpected value for attribute stringAttr",
                 "hello", sb.getStringAttr());
    assertTrue("Unexpected value for attribute booleanAttr",
               sb.getBooleanAttr());
    assertEquals("Unexpected value for attribute integerAttr",
                 BigInteger.ONE, sb.getIntegerAttr());
    assertEquals("Unexpected value for attribute intAttr",
                 Integer.valueOf(2), sb.getIntAttr());
    assertEquals("Unexpected value for attribute longAttr",
                 Long.valueOf(3L), sb.getLongAttr());
    assertEquals("Unexpected value for attribute shortAttr",
                 Short.valueOf((short)4), sb.getShortAttr());
    assertEquals("Unexpected value for attribute decimalAttr",
                 new BigDecimal("5"), sb.getDecimalAttr());
    assertEquals("Unexpected value for attribute floatAttr",
                 Float.valueOf(6F), sb.getFloatAttr());
    assertEquals("Unexpected value for attribute doubleAttr",
                 Double.valueOf(7.0D), sb.getDoubleAttr());
    assertEquals("Unexpected value for attribute byteAttr",
                 Byte.valueOf((byte)8), sb.getByteAttr());

    QName qn = sb.getQnameAttr();
    assertEquals("Unexpected value for attribute qnameAttrNoDefault",
                 "schema", qn.getLocalPart());
    assertEquals("Unexpected value for attribute qnameAttrNoDefault",
                 "http://www.w3.org/2001/XMLSchema", qn.getNamespaceURI());
    byte[] expected = DatatypeConverter.parseBase64Binary("abcd");
    byte[] val = sb.getBase64BinaryAttr();
    assertEquals("Unexpected value for attribute base64BinaryAttrNoDefault", expected.length, val.length);
    for (int i = 0; i < expected.length; i++) {
        assertEquals("Unexpected value for attribute base64BinaryAttrNoDefault", expected[i], val[i]);
    }
    expected = new HexBinaryAdapter().unmarshal("aaaa");
    val = sb.getHexBinaryAttr();
    assertEquals("Unexpected value for attribute hexBinaryAttrNoDefault", expected.length, val.length);
    for (int i = 0; i < expected.length; i++) {
        assertEquals("Unexpected value for attribute hexBinaryAttrNoDefault", expected[i], val[i]);
    }

    assertEquals("Unexpected value for attribute unsignedIntAttrNoDefault",
                 Long.valueOf(9L), sb.getUnsignedIntAttr());
    assertEquals("Unexpected value for attribute unsignedShortAttrNoDefault",
                 Integer.valueOf(10), sb.getUnsignedShortAttr());
    assertEquals("Unexpected value for attribute unsignedByteAttrNoDefault",
                 Short.valueOf((short)11), sb.getUnsignedByteAttr());
}
 
Example #21
Source File: SHAEncoder.java    From seppb with MIT License 4 votes vote down vote up
public static String encodeSHA(byte[] data) throws Exception {
	MessageDigest md = MessageDigest.getInstance("SHA");
	byte[] digest = md.digest(data);
	return new HexBinaryAdapter().marshal(digest);
}
 
Example #22
Source File: MultipleDigestInputStream.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getMessageDigestAsHexadecimalString (String algorithm)
{
   return (new HexBinaryAdapter()).marshal (
      getMessageDigest (algorithm).digest ());
}
 
Example #23
Source File: SHAEncoder.java    From seppb with MIT License 4 votes vote down vote up
public static String encodeSHA512(byte[] data) throws Exception {
	MessageDigest md = MessageDigest.getInstance("SHA-512");
	byte[] digest = md.digest(data);
	return new HexBinaryAdapter().marshal(digest);
}
 
Example #24
Source File: SHAEncoder.java    From seppb with MIT License 4 votes vote down vote up
public static String encodeSHA384(byte[] data) throws Exception {
	MessageDigest md = MessageDigest.getInstance("SHA-384");
	byte[] digest = md.digest(data);
	return new HexBinaryAdapter().marshal(digest);
}
 
Example #25
Source File: SHAEncoder.java    From seppb with MIT License 4 votes vote down vote up
public static String encodeSHA256(byte[] data) throws Exception {
	MessageDigest md = MessageDigest.getInstance("SHA-256");
	byte[] digest = md.digest(data);
	return new HexBinaryAdapter().marshal(digest);
}