Java Code Examples for org.apache.commons.codec.binary.Hex#encodeHexString()
The following examples show how to use
org.apache.commons.codec.binary.Hex#encodeHexString() .
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: TLSHHasher.java From metron with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: JvmVerification.java From beam with Apache License 2.0 | 5 votes |
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); }
Example 3
Source File: CodecUtil.java From seed with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 4
Source File: BlobA6.java From InflatableDonkey with MIT License | 5 votes |
@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()) + '}'; }
Example 5
Source File: VerifyTest.java From gradle-download-task with Apache License 2.0 | 5 votes |
/** * 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()); }
Example 6
Source File: ConfirmedRpcApiService.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
@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(); }
Example 7
Source File: HexUtil.java From openjavacard-tools with GNU Lesser General Public License v3.0 | 5 votes |
public static String bytesToHex(byte[] bytes) { if (bytes == null) { return "(null)"; } else if (bytes.length == 0) { return "(empty)"; } else { return Hex.encodeHexString(bytes); } }
Example 8
Source File: QuasarTokenEncoder.java From warp10-platform with Apache License 2.0 | 5 votes |
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()); }
Example 9
Source File: FingerprintHelper.java From oxAuth with MIT License | 5 votes |
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); }
Example 10
Source File: AccessToken.java From gocd with Apache License 2.0 | 5 votes |
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); } }
Example 11
Source File: LfsMemoryReader.java From git-as-svn with GNU General Public License v2.0 | 4 votes |
private String getSha() { return Hex.encodeHexString(HashHelper.sha256().digest(content)); }
Example 12
Source File: ContentReviewServiceTurnitinOC.java From sakai with Educational Community License v2.0 | 4 votes |
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"))); }
Example 13
Source File: Md5Utils.java From cos-java-sdk-v5 with MIT License | 4 votes |
public static String md5Hex(String utf8Content) { return Hex.encodeHexString(computeMD5Hash(utf8Content.getBytes(StringUtils.UTF8))); }
Example 14
Source File: SHA512ChecksumCompute.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@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)))); }
Example 15
Source File: MD5.java From openmeetings with Apache License 2.0 | 4 votes |
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()); }
Example 16
Source File: BlobStoreClient.java From emodb with Apache License 2.0 | 4 votes |
private String base64ToHex(String base64) { return (base64 != null) ? Hex.encodeHexString(Base64.decodeBase64(base64)) : null; }
Example 17
Source File: DigestUtils.java From JobX with Apache License 2.0 | 4 votes |
/** * Hex编码. */ public static String encodeHex(byte[] input) { return Hex.encodeHexString(input); }
Example 18
Source File: BlockUtils.java From blockchain with MIT License | 3 votes |
/** * 计算区块的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); }
Example 19
Source File: BaseEncryption.java From geowave with Apache License 2.0 | 2 votes |
/** * 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); }
Example 20
Source File: HelperFunctions.java From SPADE with GNU General Public License v3.0 | 2 votes |
/** * Create hex string from ascii * * @param string * @return converted hex string */ public static String encodeHex(String string){ return Hex.encodeHexString(String.valueOf(string).getBytes()); }