本文整理了Java中eu.europa.esig.dss.utils.Utils.toHex()
方法的一些代码示例,展示了Utils.toHex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.toHex()
方法的具体详情如下:
包路径:eu.europa.esig.dss.utils.Utils
类名称:Utils
方法名:toHex
暂无
代码示例来源:origin: esig/dss
/**
* Converts an array of bytes into a String representing the hexadecimal values of each byte in order. The returned
* String will be double the length of the passed array, as it takes two characters to represent any given byte. If
* the input array is null then null is returned. The obtained string is converted to uppercase.
*
* @param value
* the value to be converted to hexadecimal
* @return the hexadecimal String
*/
public static String toHex(final byte[] value) {
return (value != null) ? Utils.toHex(value) : null;
}
代码示例来源:origin: esig/dss
/**
* Returns a Hex encoded of the MD5 digest of binaries
*
* @param bytes
* the bytes to be digested
* @return the hex encoded MD5 digest
*/
public static String getMD5Digest(byte[] bytes) {
return Utils.toHex(digest(DigestAlgorithm.MD5, bytes));
}
代码示例来源:origin: esig/dss
/**
* This method digests the given string with SHA1 algorithm and encode returned array of bytes as hex string.
*
* @param stringToDigest
* Everything in the name
* @return hex encoded digest value
*/
public static String getSHA1Digest(final String stringToDigest) {
return Utils.toHex(digest(DigestAlgorithm.SHA1, stringToDigest.getBytes(StandardCharsets.UTF_8)));
}
代码示例来源:origin: esig/dss
@Test(expected = Exception.class)
public void toHexNull() {
Utils.toHex(null);
}
代码示例来源:origin: esig/dss
@Test
public void toHex() {
assertEquals("", Utils.toHex(new byte[] {}));
assertEquals("0102030405", Utils.toHex(new byte[] { 1, 2, 3, 4, 5 }));
assertEquals("61027a6a09", Utils.toHex(new byte[] { 'a', 2, 'z', 'j', 9 }));
}
代码示例来源:origin: esig/dss
@Test
public void digest() {
byte[] data = "Hello world!".getBytes(StandardCharsets.UTF_8);
assertEquals("d3486ae9136e7856bc42212385ea797094475802", Utils.toHex(DSSUtils.digest(DigestAlgorithm.SHA1, data)));
assertEquals("7e81ebe9e604a0c97fef0e4cfe71f9ba0ecba13332bde953ad1c66e4", Utils.toHex(DSSUtils.digest(DigestAlgorithm.SHA224, data)));
assertEquals("c0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a", Utils.toHex(DSSUtils.digest(DigestAlgorithm.SHA256, data)));
assertEquals("f6cde2a0f819314cdde55fc227d8d7dae3d28cc556222a0a8ad66d91ccad4aad6094f517a2182360c9aacf6a3dc323162cb6fd8cdffedb0fe038f55e85ffb5b6",
Utils.toHex(DSSUtils.digest(DigestAlgorithm.SHA512, data)));
assertEquals("d3ee9b1ba1990fecfd794d2f30e0207aaa7be5d37d463073096d86f8", Utils.toHex(DSSUtils.digest(DigestAlgorithm.SHA3_224, data)));
assertEquals("d6ea8f9a1f22e1298e5a9506bd066f23cc56001f5d36582344a628649df53ae8", Utils.toHex(DSSUtils.digest(DigestAlgorithm.SHA3_256, data)));
assertEquals("f9210511d0b2862bdcb672daa3f6a4284576ccb24d5b293b366b39c24c41a6918464035ec4466b12e22056bf559c7a49",
Utils.toHex(DSSUtils.digest(DigestAlgorithm.SHA3_384, data)));
assertEquals("95decc72f0a50ae4d9d5378e1b2252587cfc71977e43292c8f1b84648248509f1bc18bc6f0b0d0b8606a643eff61d611ae84e6fbd4a2683165706bd6fd48b334",
Utils.toHex(DSSUtils.digest(DigestAlgorithm.SHA3_512, data)));
}
代码示例来源:origin: esig/dss
@Test
public void getDigestSignaturePolicy() throws Exception {
FileInputStream fis = new FileInputStream("src/test/resources/signature-policy-example.der");
byte[] policyBytes = Utils.toByteArray(fis);
Utils.closeQuietly(fis);
byte[] signaturePolicyDigest = DSSASN1Utils.getAsn1SignaturePolicyDigest(DigestAlgorithm.SHA256, policyBytes);
String hexSignaturePolicyDigest = Utils.toHex(signaturePolicyDigest);
assertEquals("fe71e01aedd99f444238602d4e98f47bbab405c58c0e3811b9511dcd58c3c983", hexSignaturePolicyDigest);
}
代码示例来源:origin: esig/dss
if (LOG.isTraceEnabled()) {
LOG.trace("Timestamp digest algorithm: {}", digestAlgorithm.getName());
LOG.trace("Timestamp digest value : {}", Utils.toHex(digest));
代码示例来源:origin: esig/dss
@Test
public void getSKI() {
byte[] ski = DSSASN1Utils.getSki(certificateWithAIA);
assertEquals("4c4c4cfcacace6bb", Utils.toHex(ski));
CertificateToken certNoSKIextension = DSSUtils.loadCertificateFromBase64EncodedString(
"MIICaDCCAdSgAwIBAgIDDIOqMAoGBiskAwMBAgUAMG8xCzAJBgNVBAYTAkRFMT0wOwYDVQQKFDRSZWd1bGllcnVuZ3NiZWjIb3JkZSBmyHVyIFRlbGVrb21tdW5pa2F0aW9uIHVuZCBQb3N0MSEwDAYHAoIGAQoHFBMBMTARBgNVBAMUCjVSLUNBIDE6UE4wIhgPMjAwMDAzMjIwODU1NTFaGA8yMDA1MDMyMjA4NTU1MVowbzELMAkGA1UEBhMCREUxPTA7BgNVBAoUNFJlZ3VsaWVydW5nc2JlaMhvcmRlIGbIdXIgVGVsZWtvbW11bmlrYXRpb24gdW5kIFBvc3QxITAMBgcCggYBCgcUEwExMBEGA1UEAxQKNVItQ0EgMTpQTjCBoTANBgkqhkiG9w0BAQEFAAOBjwAwgYsCgYEAih5BUycfBpqKhU8RDsaSvV5AtzWeXQRColL9CH3t0DKnhjKAlJ8iccFtJNv+d3bh8bb9sh0maRSo647xP7hsHTjKgTE4zM5BYNfXvST79OtcMgAzrnDiGjQIIWv8xbfV1MqxxdtZJygrwzRMb9jGCAGoJEymoyzAMNG7tSdBWnUCBQDAAAABoxIwEDAOBgNVHQ8BAf8EBAMCAQYwCgYGKyQDAwECBQADgYEAOaK8ihVSBUcL2IdVBxZYYUKwMz5m7H3zqhN8W9w+iafWudH6b+aahkbENEwzg3C3v5g8nze7v7ssacQze657LHjP+e7ksUDIgcS4R1pU2eN16bjSP/qGPF3rhrIEHoK5nJULkjkZYTtNiOvmQ/+G70TXDi3Os/TwLlWRvu+7YLM=");
assertNull(DSSASN1Utils.getSki(certNoSKIextension));
assertNull(DSSASN1Utils.getSki(certNoSKIextension, false));
assertNotNull(DSSASN1Utils.getSki(certNoSKIextension, true));
CertificateToken c1 = DSSUtils.loadCertificateFromBase64EncodedString(
"MIIF3DCCBMSgAwIBAgIBCTANBgkqhkiG9w0BAQUFADCBzjELMAkGA1UEBhMCSFUxETAPBgNVBAcTCEJ1ZGFwZXN0MR0wGwYDVQQKExRNQVYgSU5GT1JNQVRJS0EgS2Z0LjEYMBYGA1UECxMPUEtJIFNlcnZpY2VzIEJVMSAwHgYDVQQDDBdUcnVzdCZTaWduIFJvb3QgQ0EgdjEuMDEcMBoGA1UECRMTS3Jpc3p0aW5hIGtydC4gMzcvQTENMAsGA1UEERMEMTAxMjEkMCIGCSqGSIb3DQEJARYVaWNhQG1hdmluZm9ybWF0aWthLmh1MB4XDTAzMDkwNTEyMjAyNloXDTEyMDkwNTEyMjAyNlowgcoxCzAJBgNVBAYTAkhVMREwDwYDVQQHEwhCdWRhcGVzdDEdMBsGA1UEChMUTUFWIElORk9STUFUSUtBIEtmdC4xGDAWBgNVBAsTD1BLSSBTZXJ2aWNlcyBCVTEcMBoGA1UEAwwTVHJ1c3QmU2lnbiBUU0EgdjEuMDEcMBoGA1UECRMTS3Jpc3p0aW5hIGtydC4gMzcvYTENMAsGA1UEERMEMTAxMjEkMCIGCSqGSIb3DQEJARYVaWNhQG1hdmluZm9ybWF0aWthLmh1MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvjiELLKGYCv7mFmAcJPeF21gG1At2dlLM8rr5KxPlaIWfvNZ6CGCuzaIEFnHbl+DSLoQKwc6EFm6eXLiU/v2TEVZBtg7V8qgFOc7cXd+8lUo+Iog1anvid16Z3MLt+5xLY+orDNbeFR39nbATladtE/qpY5Etnq9S5xFqFMHAW0vQuF3JlIZ7BoTnLgxcetCWe3oJgQ/y4L9PbfYHCEJnUU2OwCCKT6hgPijKOaDS+4QpTFgXTl/lAl/poYXZuhaFpzPBp9zwXlxoGmgjD9IZld49c3Np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BAQCtAQg42z/hSomwtQMxfVdi0oZN/vFOlP6huYbeOyj53t9Rbt6OufbuWGdRmJgckvzOzai4wqm0EDPoX72eZjrQi5mbIqeA1cOgL2FNESGwMEVvOq7MfTtVuBB592dMtaFMzjiX9FnS2yDlyzkBNttDp5KaCPJg1/R65PvdU9Ix03L1wGRlkxiU6Ozd7+ldA/HTj6HUShGgbqc24ZjWi7NnfoUMz3azn9Qk7VNWxg7mMjdj4YXgtDZ++t0h+Y/sax3+IazOV9bAkA8/wmh7TuabluTLzRHyn5hlVgPxtqmV9xlgMU2H0QXaQOEDw39pzoUJ0r06P6J45HM4IxpJyah4");
byte[] skiC1 = DSSASN1Utils.getSki(c1);
assertNotNull(skiC1);
byte[] skiC2 = DSSASN1Utils.getSki(c2);
assertNotNull(skiC2);
assertFalse(Arrays.equals(skiC1, skiC2));
byte[] encodedPKC1 = c1.getPublicKey().getEncoded();
byte[] encodedPKC2 = c2.getPublicKey().getEncoded();
assertArrayEquals(encodedPKC1, encodedPKC2);
byte[] fixedSkiC1 = DSSASN1Utils.computeSkiFromCert(c1);
byte[] fixedSkiC2 = DSSASN1Utils.computeSkiFromCert(c2);
assertArrayEquals(fixedSkiC1, fixedSkiC2);
}
内容来源于网络,如有侵权,请联系作者删除!