List of usage examples for org.apache.commons.codec.binary Hex encodeHexString
public static String encodeHexString(byte[] data)
From source file:net.solarnetwork.node.hw.sma.test.SmaPacketTest.java
@Test public void encodeNetStart() { SmaPacket p = SmaPacket.netStartPacket(0); byte[] packet = p.getPacket(); log.debug("Got packet: " + Hex.encodeHexString(packet)); assertNotNull("Packet", packet); assertArrayEquals(TestUtils.bytesFromHexString("00 00 00 00 80 00 06"), packet); }
From source file:com.hurence.logisland.util.string.Anonymizer.java
public String anonymize(String str) throws NoSuchAlgorithmException, InvalidKeySpecException { // Hash the password PBEKeySpec spec = new PBEKeySpec(str.toCharArray(), salt, PBKDF2_ITERATIONS, HASH_BYTE_SIZE * 8); SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM); byte[] hash = skf.generateSecret(spec).getEncoded(); return Hex.encodeHexString(hash); }
From source file:net.mooncloud.hadoop.hive.ql.udf.UDFMd5.java
/** * Convert String to md5/*ww w . j av a2s . c o m*/ */ public Text evaluate(Text n) { if (n == null) { return null; } digest.reset(); digest.update(n.getBytes(), 0, n.getLength()); byte[] md5Bytes = digest.digest(); String md5Hex = Hex.encodeHexString(md5Bytes); result.set(md5Hex); return result; }
From source file:net.shibboleth.idp.attribute.ByteAttributeValue.java
/** * Get this value as a hex-encoded string. * * @return a hex-encoded string */ @Nonnull public String toHex() { return Hex.encodeHexString(value); }
From source file:com.pkrete.locationservice.admin.converter.encryption.BasicEncryptionService.java
/** * Encrypts the given string by using SHA algorithm and converts the result * to a corresponding hex string. The string must be UTF-8 encoded. * * @param plaintext string to be encrypted * @return encrypted string/*from w w w . j a v a 2 s.c om*/ */ @Override public String encrypt(String plaintext) { try { // Get new MessageDigest object using SHA algorithm MessageDigest digester = MessageDigest.getInstance(ALOGORITHM); // Encode the credentials using UTF-8 character encoding digester.update(plaintext.getBytes(ENCODING)); // Digest the credentials and return as hexadecimal return (Hex.encodeHexString(digester.digest())); } catch (Exception ex) { logger.error(ex.getMessage(), ex); return plaintext; } }
From source file:ch.cyberduck.core.irods.IRODSAttributesFinderFeature.java
@Override public PathAttributes find(final Path file) throws BackgroundException { try {//ww w. j av a2 s .c om final IRODSFileSystemAO fs = session.getClient(); final IRODSFile f = fs.getIRODSFileFactory().instanceIRODSFile(file.getAbsolute()); if (!f.exists()) { throw new NotfoundException(file.getAbsolute()); } final PathAttributes attributes = new PathAttributes(); final ObjStat stats = fs.getObjStat(f.getAbsolutePath()); attributes.setModificationDate(stats.getModifiedAt().getTime()); attributes.setCreationDate(stats.getCreatedAt().getTime()); attributes.setSize(stats.getObjSize()); attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(stats.getChecksum())))); attributes.setOwner(stats.getOwnerName()); attributes.setGroup(stats.getOwnerZone()); return attributes; } catch (JargonException e) { throw new IRODSExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }
From source file:net.michaelpigg.xbeelib.protocol.XbeeAddressTest.java
public void test16BitCombinedAddress() throws DecoderException { logger.info("test16BitCombinedAddress"); XbeeAddress address = XbeeAddress.getAddress(new byte[] { 0x0, 0x1 }); byte[] combinedAddress = address.getCombinedAddress(); final byte[] expected = ArrayUtils.addAll(XbeeAddress.BROADCAST_64_BIT, new byte[] { 0x0, 0x1 }); logger.info("actual value {}", Hex.encodeHexString(combinedAddress)); logger.info("expected value {}", Hex.encodeHexString(expected)); assertEquals(combinedAddress, expected); }
From source file:architecture.common.license.validator.CheckSignatureValidator.java
public void validate(License license) throws LicenseException { try {//from w ww. ja va 2 s.c o m // DSA ? . String publicKey = "308201b83082012c06072a8648ce3804013082011f02818100fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c70215009760508f15230bccb292b982a2eb840bf0581cf502818100f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a0381850002818100faf2d25b2866aa68501094d1097bebc95c6bcf1c58766f18b35fbf5e9d761cc5bf913447e374c21d279777859f9f043d1dc0d58b93a2081b56b4f5269a81b076907a3b11b01ec5cfde5dae4dfd7d26346e53e611235e714e69ec1bc141c77a8a28c4c799df570a4c3240e7f2fee19d6ed4caaa1b15b5da4a967ee82e3eb4d4ca"; byte pub[] = Hex.decodeHex(publicKey.toCharArray()); X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(pub); KeyFactory keyFactory = KeyFactory.getInstance("DSA"); java.security.PublicKey pubKey = keyFactory.generatePublic(pubKeySpec); Signature sig = Signature.getInstance("DSA"); sig.initVerify(pubKey); // license.getSignature().getBytes("UTF-8"); byte decoded[] = Hex.decodeHex(license.getSignature().toCharArray()); log.debug("decoded sig: " + Hex.encodeHexString(decoded)); log.info((new StringBuilder()).append("Validating license. License fingerprint: ") .append(license.getSignature()).toString()); sig.update(license.getFingerprint()); boolean verified = sig.verify(decoded); if (!verified) throw new LicenseException("License signature is invalid."); } catch (Exception e) { log.fatal(e.getMessage(), e); throw new LicenseException(e); } }
From source file:de.resol.vbus.LiveOutputStreamTest.java
@Test public void testWriteHeader() throws Exception { Datagram refDgram1 = new Datagram(0, 0, 0x2336, 0x3335, 0x4334, 0x5333, 0x63328330); PipedInputStream refIs1 = new PipedInputStream(2048); PipedOutputStream refOs1 = new PipedOutputStream(refIs1); LiveOutputStream testOs1 = new LiveOutputStream(refOs1); testOs1.writeHeader(refDgram1);/* w w w . ja v a 2 s .co m*/ byte[] testBuffer1 = new byte[32]; int testLength1 = refIs1.read(testBuffer1); assertEquals(16, testLength1); assertEquals("aa362335332034433353300332630851", Hex.encodeHexString(testBuffer1).substring(0, 32)); }
From source file:net.solarnetwork.node.rfxcom.test.SetModeMessageTest.java
@Test public void encodeSetModeCommand1() { SetModeMessage msg = new SetModeMessage((short) 27, TransceiverType.Type43392a); msg.setOregonEnabled(true);/*from w ww . j av a 2s.c o m*/ final byte[] packet = msg.getMessagePacket(); log.debug("Got packet: " + Hex.encodeHexString(packet)); assertNotNull("Packet", packet); assertArrayEquals(TestUtils.bytesFromHexString("0D 00 00 1B 03 53 00 00 00 20 00 00 00 00"), packet); }