List of usage examples for javax.xml.bind DatatypeConverter printHexBinary
public static String printHexBinary(byte[] val)
Converts an array of bytes into a string.
From source file:org.seedstack.seed.crypto.internal.PasswordLookupTest.java
/** * Test method for {@link org.seedstack.seed.crypto.internal.PasswordLookup#lookup(java.lang.String)}. * /*from w w w.j av a 2s . co m*/ * @throws Exception if an error occurred */ @Test public void testLookupString(@Mocked final AbstractConfiguration configuration, @Mocked final EncryptionService service) throws Exception { final String toDecrypt = "essai crypting"; final String cryptingString = DatatypeConverter.printHexBinary(toDecrypt.getBytes()); new Expectations() { { service.decrypt(DatatypeConverter.parseHexBinary(cryptingString)); result = toDecrypt.getBytes(); } }; PasswordLookup lookup = new PasswordLookup(configuration); Deencapsulation.setField(lookup, "encryptionService", service); Assertions.assertThat(lookup.lookup(cryptingString)).isEqualTo(toDecrypt); }
From source file:org.seedstack.seed.crypto.internal.PasswordLookupTest.java
/** * Test method for {@link org.seedstack.seed.crypto.internal.PasswordLookup#lookup(java.lang.String)}. * //w ww . java 2 s. c om * @throws Exception if an error occurred */ @Test(expected = RuntimeException.class) public void testLookupStringWithInvalidKey(@Mocked final AbstractConfiguration configuration, @Mocked final EncryptionService service) throws Exception { final String toDecrypt = "essai crypting"; final String cryptingString = DatatypeConverter.printHexBinary(toDecrypt.getBytes()); new Expectations() { { service.decrypt(DatatypeConverter.parseHexBinary(cryptingString)); result = new InvalidKeyException("dummy exception"); } }; PasswordLookup lookup = new PasswordLookup(configuration); Deencapsulation.setField(lookup, "encryptionService", service); lookup.lookup(cryptingString); }
From source file:org.zuinnote.hadoop.bitcoin.format.BitcoinUtil.java
/** * Converts a Byte Array to Hex String. Only used for configuration not for parsing. Hex String is in format of xsd:hexBinary * * @param byteArray byte array to convert * * @return String in Hex format corresponding to byteArray * *//* w ww.j av a2 s .c o m*/ public static String convertByteArrayToHexString(byte[] byteArray) { return DatatypeConverter.printHexBinary(byteArray); }
From source file:sf.net.experimaestro.manager.Manager.java
/** * Get the hash of a given json//www . ja v a 2 s . c o m */ public static String getDigest(Json json) throws NoSuchAlgorithmException, IOException { // Other options: SHA-256, SHA-512 MessageDigestWriter writer = new MessageDigestWriter(Charset.forName("UTF-8"), "MD5"); json.writeDescriptorString(writer); writer.close(); return DatatypeConverter.printHexBinary(writer.getDigest()).toLowerCase(); }
From source file:snow.utils.MDigest.java
public static String md(String algorithm, byte[] bytes) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance(algorithm); md.update(bytes);/*from w w w. ja v a 2s . c o m*/ return DatatypeConverter.printHexBinary(md.digest()); }