Java Code Examples for org.apache.commons.codec.binary.Hex#encodeHex()

The following examples show how to use org.apache.commons.codec.binary.Hex#encodeHex() . 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: MD4PasswordEncoderImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private String encodeInternal(String input)
{
    if (!getEncodeHashAsBase64())
    {
        return new String(Hex.encodeHex(md4(input)));
    }

    byte[] encoded = Base64.encodeBase64(md4(input));

    try
    {
        return new String(encoded, "UTF8");
    }
    catch (UnsupportedEncodingException e)
    {
        throw new RuntimeException("UTF8 not supported!", e);
    }
}
 
Example 2
Source File: AESEncrypt.java    From quark with Apache License 2.0 5 votes vote down vote up
public String convertToDatabaseColumn(String phrase) throws SQLException {
  try {
    Cipher encryptCipher = Cipher.getInstance("AES");
    encryptCipher.init(Cipher.ENCRYPT_MODE,
        generateMySQLAESKey(this.key, "UTF-8"));

    return new String(Hex.encodeHex(encryptCipher.doFinal(phrase.getBytes("UTF-8"))));
  } catch (Exception e) {
    throw new SQLException(e);
  }
}
 
Example 3
Source File: HashUtil.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static String md5(String plaintext) {
try {
    MessageDigest md = MessageDigest.getInstance("MD5");
    return new String(Hex.encodeHex(md.digest(plaintext.getBytes())));
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
}
   }
 
Example 4
Source File: DatabaseAdaptor.java    From KeePassJava2 with Apache License 2.0 5 votes vote down vote up
@Override
public String getHash() {
    byte[] toHash = Helpers.hexStringFromUuid(database.getRootGroup().getUuid()).getBytes();
    SHA1Digest digest = new SHA1Digest();
    byte[] digestBytes = new byte[digest.getDigestSize()];
    digest.update(toHash, 0, toHash.length);
    digest.doFinal(digestBytes, 0);
    String result = new String(Hex.encodeHex(digestBytes));
    return result.toLowerCase();
}
 
Example 5
Source File: HmacSHA256Signer.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
/**
 * Sign the given message using the given secret.
 * @param message message to sign
 * @param secret secret key
 * @return a signed message
 */
public static String sign(String message, String secret) {
  try {
    Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
    SecretKeySpec secretKeySpec = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
    sha256_HMAC.init(secretKeySpec);
    return new String(Hex.encodeHex(sha256_HMAC.doFinal(message.getBytes())));
  } catch (Exception e) {
    throw new RuntimeException("Unable to sign message.", e);
  }
}
 
Example 6
Source File: SecurityKeyUtil.java    From peer-os with Apache License 2.0 5 votes vote down vote up
/********************************************
 * Convert BouncyCastle PGPKey to SecurityKey entity
 */
public static PublicKeyStore convert( PGPPublicKey pgpKey ) throws IOException
{
    String fingerprint = new String( Hex.encodeHex( pgpKey.getFingerprint(), false ) );

    PublicKeyStore pk = new PublicKeyStoreEntity();

    pk.setFingerprint( fingerprint );
    pk.setKeyId( PGPKeyUtil.getKeyId( fingerprint ) );
    pk.setShortKeyId( PGPKeyUtil.getShortKeyId( fingerprint ) );
    pk.setKeyData( pgpKey.getPublicKeyPacket().getEncoded() );


    return pk;
}
 
Example 7
Source File: ArchiveFileContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
/**
 * Stores the hash of a written content file in the transaction for potential clients to pick up.
 *
 * @param writer
 *            the writer used to write the content file
 */
protected void txnStoreHash(final ArchvieFileContentWriterImpl writer)
{
    final Map<String, String> map = TransactionalResourceHelper.getMap(TXN_CONTENT_URL_HASHES);
    final byte[] digest = writer.getDigest();
    final char[] digestCh = Hex.encodeHex(digest, false);
    final String digestStr = new String(digestCh);
    final String digestVal = this.digestAlgorithm.toLowerCase(Locale.ENGLISH) + ':' + digestStr;
    map.put(writer.getContentUrl(), digestVal);
}
 
Example 8
Source File: HashUtil.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static String sha1(String plaintext) {
try {
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    return new String(Hex.encodeHex(md.digest(plaintext.getBytes())));
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
}
   }
 
Example 9
Source File: WxCommonUtil.java    From roncoo-pay with Apache License 2.0 5 votes vote down vote up
/**
 * 文件转MD5Hash
 *
 * @param fis
 * @return
 */
public static String md5HashCode(InputStream fis) {
    try {
        MessageDigest MD5 = MessageDigest.getInstance("MD5");
        byte[] buffer = new byte[8192];
        int length;
        while ((length = fis.read(buffer)) != -1) {
            MD5.update(buffer, 0, length);
        }
        return new String(Hex.encodeHex(MD5.digest()));
    } catch (Exception e) {
        logger.error(e.getMessage());
        return null;
    }
}
 
Example 10
Source File: UserProfileBean.java    From openzaly with Apache License 2.0 5 votes vote down vote up
public String getGlobalUserId() {
	if (StringUtils.isEmpty(this.globalUserId)) {
		String body = this.userIdPubk;
		String SHA1UserPubKey = new String(Hex.encodeHex(DigestUtils.sha1(body)));

		CRC32 c32 = new CRC32();
		c32.update(body.getBytes(), 0, body.getBytes().length);
		String CRC32UserPubKey = String.valueOf(c32.getValue());

		return SHA1UserPubKey + "-" + CRC32UserPubKey;
	}
	return this.globalUserId;
}
 
Example 11
Source File: Md5PwdEncoder.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
public String encodePassword(String rawPass, String salt) {
	String saltedPass = mergePasswordAndSalt(rawPass, salt, false);
	MessageDigest messageDigest = getMessageDigest();
	byte[] digest;
	try {
		digest = messageDigest.digest(saltedPass.getBytes("UTF-8"));
	} catch (UnsupportedEncodingException e) {
		throw new IllegalStateException("UTF-8 not supported!");
	}
	return new String(Hex.encodeHex(digest));
}
 
Example 12
Source File: DynamicKey5.java    From dbys with GNU General Public License v3.0 5 votes vote down vote up
public static String generateSignature(String appCertificate, short service, String appID, int unixTs, int salt, String channelName, long uid, int expiredTs, TreeMap<Short, String> extra) throws Exception {
    // decode hex to avoid case problem
    Hex hex = new Hex();
    byte[] rawAppID = hex.decode(appID.getBytes());
    byte[] rawAppCertificate = hex.decode(appCertificate.getBytes());

    Message m = new Message(service, rawAppID, unixTs, salt, channelName, (int)(uid & 0xFFFFFFFFL), expiredTs, extra);
    byte[] toSign = pack(m);
    return new String(Hex.encodeHex(DynamicKeyUtil.encodeHMAC(rawAppCertificate, toSign), false));
}
 
Example 13
Source File: UserProfileBean.java    From openzaly with Apache License 2.0 5 votes vote down vote up
public String getGlobalUserId() {
	if (StringUtils.isEmpty(this.globalUserId)) {
		String body = this.userIdPubk;
		String SHA1UserPubKey = new String(Hex.encodeHex(DigestUtils.sha1(body)));

		CRC32 c32 = new CRC32();
		c32.update(body.getBytes(), 0, body.getBytes().length);
		String CRC32UserPubKey = String.valueOf(c32.getValue());

		return SHA1UserPubKey + "-" + CRC32UserPubKey;
	}
	return this.globalUserId;
}
 
Example 14
Source File: Bytes.java    From hugegraph-common with Apache License 2.0 4 votes vote down vote up
public static String toHex(byte[] bytes) {
    return new String(Hex.encodeHex(bytes));
}
 
Example 15
Source File: ContactMatcherUtils.java    From buddycloud-android with Apache License 2.0 4 votes vote down vote up
public static String hash(String provider, String id) {
	return new String(Hex.encodeHex(DigestUtils.sha256(provider + ":" + id)));
}
 
Example 16
Source File: EncodeUtil.java    From hdw-dubbo with Apache License 2.0 4 votes vote down vote up
/**
 * Hex编码.
 */
public static String encodeHex(byte[] input) {
    return new String(Hex.encodeHex(input));
}
 
Example 17
Source File: OSMWay.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public String checksum() {
    String str = preChecksum();
    return new String(Hex.encodeHex(DigestUtils.sha1(str)));
}
 
Example 18
Source File: Encodes.java    From super-cloudops with Apache License 2.0 4 votes vote down vote up
/**
 * Hex编码.
 */
public static String encodeHex(byte[] input) {
	return new String(Hex.encodeHex(input));
}
 
Example 19
Source File: DccClient.java    From bce-sdk-java with Apache License 2.0 3 votes vote down vote up
/**
 * The encryption implement for AES-128 algorithm for BCE password encryption.
 * Only the first 16 bytes of privateKey will be used to encrypt the content.
 * <p>
 * See more detail on
 * <a href = "https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF">
 * BCE API doc</a>
 *
 * @param content    The content String to encrypt.
 * @param privateKey The security key to encrypt.
 *                   Only the first 16 bytes of privateKey will be used to encrypt the content.
 * @return The encrypted string of the original content with AES-128 algorithm.
 * @throws GeneralSecurityException
 */
private String aes128WithFirst16Char(String content, String privateKey) throws GeneralSecurityException {
    byte[] crypted = null;
    SecretKeySpec skey = new SecretKeySpec(privateKey.substring(0, 16).getBytes(), "AES");
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
    cipher.init(Cipher.ENCRYPT_MODE, skey);
    crypted = cipher.doFinal(content.getBytes());
    return new String(Hex.encodeHex(crypted));
}
 
Example 20
Source File: CryptoServiceSingleton.java    From wisdom with Apache License 2.0 2 votes vote down vote up
/**
 * Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.
 * <p>
 * This method is just there to avoid consumers using commons-codec directly.
 *
 * @param bytes the bytes
 * @return the hexadecimal characters.
 */
@Override
public char[] hex(byte[] bytes) {
    return Hex.encodeHex(bytes);
}