org.apache.commons.codec.binary.Hex # encodeHexString ( ) 源码实例Demo

下面列出了 org.apache.commons.codec.binary.Hex # encodeHexString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: metron   文件: TLSHHasher.java

public Map<String, String> bin(String hash) throws DecoderException {
  Random r = new Random(0);
  byte[] h = Hex.decodeHex(hash.substring(2 * checksumOption.getChecksumLength()).toCharArray());
  BitSet vector = BitSet.valueOf(h);
  int n = vector.length();
  Map<String, String> ret = new HashMap<>();
  boolean singleHash = hashes.size() == 1;
  for (int numHashes : hashes) {
    BitSet projection = new BitSet();
    for (int i = 0; i < numHashes; ++i) {
      int index = r.nextInt(n);
      projection.set(i, vector.get(index));
    }
    String outputHash = numHashes + Hex.encodeHexString(projection.toByteArray());
    if (singleHash) {
      ret.put(TLSH_BIN_KEY, outputHash);
    } else {
      ret.put(TLSH_BIN_KEY + "_" + numHashes, outputHash);
    }
  }
  return ret;
}
 
源代码2 项目: gocd   文件: AccessToken.java

static String digestToken(String originalToken, String salt) {
    try {
        ACCESS_TOKEN_LOGGER.debug("Generating secret using algorithm: {} with spec: DEFAULT_ITERATIONS: {}, DESIRED_KEY_LENGTH: {}", KEY_ALGORITHM, DEFAULT_ITERATIONS, DESIRED_KEY_LENGTH);
        SecretKeyFactory factory = SecretKeyFactory.getInstance(KEY_ALGORITHM);
        SecretKey key = factory.generateSecret(new PBEKeySpec(originalToken.toCharArray(), salt.getBytes(), DEFAULT_ITERATIONS, DESIRED_KEY_LENGTH));
        return Hex.encodeHexString(key.getEncoded());
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        throw new RuntimeException(e);
    }
}
 
源代码3 项目: oxAuth   文件: FingerprintHelper.java

public static String getPublicKeySshFingerprint(RSAPublicKey publicKey) throws NoSuchAlgorithmException, IOException {
	MessageDigest digest = MessageDigest.getInstance("MD5");

	byte[] derEncoded = getDerEncoding(publicKey);
	byte[] fingerprint = digest.digest(derEncoded);

	return Hex.encodeHexString(fingerprint);
}
 

public String getTokenIdent(String token, byte[] tokenSipHashkey) {
  long ident = SipHashInline.hash24_palindromic(tokenSipHashkey, token.getBytes());

  ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
  buffer.order(ByteOrder.BIG_ENDIAN);
  buffer.putLong(ident);
  return Hex.encodeHexString(buffer.array());
}
 
源代码5 项目: openjavacard-tools   文件: HexUtil.java

public static String bytesToHex(byte[] bytes) {
    if (bytes == null) {
        return "(null)";
    } else if (bytes.length == 0) {
        return "(empty)";
    } else {
        return Hex.encodeHexString(bytes);
    }
}
 
源代码6 项目: gsc-core   文件: ConfirmedRpcApiService.java

@Override
public void generateAddress(EmptyMessage request,
                            StreamObserver<AddressPrKeyPairMessage> responseObserver) {
    ECKey ecKey = new ECKey(Utils.getRandom());
    byte[] priKey = ecKey.getPrivKeyBytes();
    byte[] address = ecKey.getAddress();
    String addressStr = Wallet.encode58Check(address);
    String priKeyStr = Hex.encodeHexString(priKey);
    AddressPrKeyPairMessage.Builder builder = AddressPrKeyPairMessage.newBuilder();
    builder.setAddress(addressStr);
    builder.setPrivateKey(priKeyStr);
    responseObserver.onNext(builder.build());
    responseObserver.onCompleted();
}
 
源代码7 项目: gradle-download-task   文件: VerifyTest.java

/**
 * Calculates the MD5 checksum for {@link #CONTENTS}
 * @return the checksum
 */
private String calculateChecksum() {
    MessageDigest md5;
    try {
        md5 = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
    md5.update(CONTENTS.getBytes(StandardCharsets.UTF_8));
    return Hex.encodeHexString(md5.digest());
}
 
源代码8 项目: InflatableDonkey   文件: BlobA6.java

@Override
public String toString() {
    return "BlobA6{"
            + "type=0x" + Integer.toHexString(type())
            + ",length=0x" + Integer.toHexString(length())
            + ", x=" + x
            + ", tag=0x" + Hex.encodeHexString(tag)
            + ", m2=0x" + Hex.encodeHexString(m2())
            + ", iv=0x" + Hex.encodeHexString(iv())
            + ", data=0x" + Hex.encodeHexString(data())
            + '}';
}
 
源代码9 项目: seed   文件: CodecUtil.java

/**
 * AES-PKCS7算法加密数据
 * 兼容IOS中的SecKeyWrapper加解密(SecKeyWrapper采用的是PKCS7Padding填充方式)
 * @param data 待加密的明文字符串
 * @param key  AES密钥字符串
 * @return AES-PKCS7加密后的16进制表示的密文字符串,加密过程中遇到异常则抛出RuntimeException
 */
public static String buildAESPKCS7Encrypt(String data, String key){
    Security.addProvider(new BouncyCastleProvider());
    try{
        SecretKey secretKey = new SecretKeySpec(Hex.decodeHex(key.toCharArray()), ALGORITHM_AES_PKCS7);
        Cipher cipher = Cipher.getInstance(ALGORITHM_CIPHER_AES_PKCS7);
        cipher.init(Cipher.ENCRYPT_MODE, secretKey, initIV());
        return Hex.encodeHexString(cipher.doFinal(data.getBytes(SeedConstants.DEFAULT_CHARSET)));
    }catch(Exception e){
        throw new RuntimeException("加密字符串[" + data + "]时遇到异常", e);
    }
}
 
源代码10 项目: beam   文件: JvmVerification.java

private static <T> Java getByteCodeVersion(final Class<T> clazz) throws IOException {
  final InputStream stream =
      clazz.getClassLoader().getResourceAsStream(clazz.getName().replace(".", "/") + ".class");
  final byte[] classBytes = IOUtils.toByteArray(stream);
  final String versionInHexString =
      Hex.encodeHexString(new byte[] {classBytes[6], classBytes[7]});
  return versionMapping.get(versionInHexString);
}
 
源代码11 项目: openmeetings   文件: MD5.java

public static String checksum(String data) throws NoSuchAlgorithmException {
	MessageDigest md5 = MessageDigest.getInstance("MD5");
	byte[] b = data == null ? new byte[0] : data.getBytes(UTF_8);
	md5.update(b, 0, b.length);
	return Hex.encodeHexString(md5.digest());
}
 
源代码12 项目: cyberduck   文件: SHA512ChecksumCompute.java

@Override
public Checksum compute(final InputStream in, final TransferStatus status) throws ChecksumException {
    return new Checksum(HashAlgorithm.sha512, Hex.encodeHexString(this.digest("SHA-512",
        this.normalize(in, status))));
}
 
源代码13 项目: cos-java-sdk-v5   文件: Md5Utils.java

public static String md5Hex(String utf8Content) {
    return Hex.encodeHexString(computeMD5Hash(utf8Content.getBytes(StringUtils.UTF8)));
}
 
源代码14 项目: git-as-svn   文件: LfsMemoryReader.java

private String getSha() {
  return Hex.encodeHexString(HashHelper.sha256().digest(content));
}
 

public static String getSigningSignature(byte[] key, String data) throws Exception {
	Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
	SecretKeySpec secret_key = new SecretKeySpec(key, "HmacSHA256");
	sha256_HMAC.init(secret_key);
	return Hex.encodeHexString(sha256_HMAC.doFinal(data.getBytes("UTF-8")));
}
 
源代码16 项目: emodb   文件: BlobStoreClient.java

private String base64ToHex(String base64) {
    return (base64 != null) ? Hex.encodeHexString(Base64.decodeBase64(base64)) : null;
}
 
源代码17 项目: JobX   文件: DigestUtils.java

/**
 * Hex编码.
 */
public static String encodeHex(byte[] input) {
    return Hex.encodeHexString(input);
}
 
源代码18 项目: blockchain   文件: BlockUtils.java

/**
 * 计算区块的hash值
 * 
 * @param block
 *            区块
 * @return
 */
public static String calculateHash(Block block) {
	String record = (block.getIndex()) + block.getTimestamp() + (block.getVac()) + block.getPrevHash();
	MessageDigest digest = DigestUtils.getSha256Digest();
	byte[] hash = digest.digest(StringUtils.getBytesUtf8(record));
	return Hex.encodeHexString(hash);
}
 
源代码19 项目: SPADE   文件: HelperFunctions.java

/**
 * Create hex string from ascii
 * 
 * @param string
 * @return converted hex string
 */
public static String encodeHex(String string){
	return Hex.encodeHexString(String.valueOf(string).getBytes());
}
 
源代码20 项目: geowave   文件: BaseEncryption.java

/**
 * Converts a binary value to a encoded string
 *
 * @param data Binary value to encode as an encoded string
 * @return Encoded string from the binary value specified
 */
private String toString(final byte[] data) {
  return Hex.encodeHexString(data);
}