本文整理了Java中org.apache.commons.codec.binary.Hex.decodeHex()
方法的一些代码示例,展示了Hex.decodeHex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hex.decodeHex()
方法的具体详情如下:
包路径:org.apache.commons.codec.binary.Hex
类名称:Hex
方法名:decodeHex
[英]Converts a String representing hexadecimal values into an array of bytes of those same values. The returned array will be half the length of the passed String, as it takes two characters to represent any given byte. An exception is thrown if the passed String has an odd number of elements.
[中]将表示十六进制值的字符串转换为具有相同值的字节数组。返回的数组将是传递字符串长度的一半,因为它需要两个字符来表示任何给定的字节。如果传递的字符串包含奇数个元素,则引发异常。
代码示例来源:origin: commons-codec/commons-codec
/**
* Converts a String representing hexadecimal values into an array of bytes of those same values. The
* returned array will be half the length of the passed String, as it takes two characters to represent any given
* byte. An exception is thrown if the passed String has an odd number of elements.
*
* @param data
* A String containing hexadecimal digits
* @return A byte array containing binary data decoded from the supplied char array.
* @throws DecoderException
* Thrown if an odd number or illegal of characters is supplied
* @since 1.11
*/
public static byte[] decodeHex(final String data) throws DecoderException {
return decodeHex(data.toCharArray());
}
代码示例来源:origin: traccar/traccar
public static byte[] parseHex(String string) {
try {
return Hex.decodeHex(string);
} catch (DecoderException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: commons-codec/commons-codec
/**
* Converts a buffer of character bytes representing hexadecimal values into an array of bytes of those same values.
* The returned array will be half the length of the passed array, as it takes two characters to represent any given
* byte. An exception is thrown if the passed char array has an odd number of elements.
*
* @param buffer
* An array of character bytes containing hexadecimal digits
* @return A byte array containing binary data decoded from the supplied byte array (representing characters).
* @throws DecoderException
* Thrown if an odd number of characters is supplied to this function
* @see #decodeHex(char[])
* @since 1.11
*/
public byte[] decode(final ByteBuffer buffer) throws DecoderException {
return decodeHex(new String(buffer.array(), getCharset()).toCharArray());
}
代码示例来源:origin: commons-codec/commons-codec
/**
* Converts an array of character bytes representing hexadecimal values into an array of bytes of those same values.
* The returned array will be half the length of the passed array, as it takes two characters to represent any given
* byte. An exception is thrown if the passed char array has an odd number of elements.
*
* @param array
* An array of character bytes containing hexadecimal digits
* @return A byte array containing binary data decoded from the supplied byte array (representing characters).
* @throws DecoderException
* Thrown if an odd number of characters is supplied to this function
* @see #decodeHex(char[])
*/
@Override
public byte[] decode(final byte[] array) throws DecoderException {
return decodeHex(new String(array, getCharset()).toCharArray());
}
代码示例来源:origin: voldemort/voldemort
public byte[] getCheckSum() throws DecoderException {
String checkSumString = (String) get(ReadOnlyStorageMetadata.CHECKSUM);
if(checkSumString == null) {
return null;
}
return Hex.decodeHex(checkSumString.toCharArray());
}
代码示例来源:origin: voldemort/voldemort
public byte[] getCheckSum() throws DecoderException {
String checkSumString = (String) get(ReadOnlyStorageMetadata.CHECKSUM);
if(checkSumString == null) {
return null;
}
return Hex.decodeHex(checkSumString.toCharArray());
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public void writeSchemaVersioningInformation(Schema schema, DataOutputStream outputStream)
throws IOException {
String schemaId = this.schemaId.isPresent() ? this.schemaId.get() : this.getIdForSchema(schema);
outputStream.writeByte(KafkaAvroSchemaRegistry.MAGIC_BYTE);
try {
outputStream.write(Hex.decodeHex(schemaId.toCharArray()));
} catch (DecoderException exception) {
throw new IOException(exception);
}
}
代码示例来源:origin: apache/nifi
private static SecretKey getMasterKey() throws KeyManagementException {
try {
// Get the master encryption key from bootstrap.conf
String masterKeyHex = NiFiPropertiesLoader.extractKeyFromBootstrapFile();
return new SecretKeySpec(Hex.decodeHex(masterKeyHex.toCharArray()), "AES");
} catch (IOException | DecoderException e) {
logger.error("Encountered an error: ", e);
throw new KeyManagementException(e);
}
}
}
代码示例来源:origin: alibaba/jstorm
public BlowfishTupleSerializer(Kryo kryo, Map storm_conf) {
String encryption_key = null;
try {
encryption_key = (String) storm_conf.get(SECRET_KEY);
LOG.debug("Blowfish serializer being constructed ...");
if (encryption_key == null) {
throw new RuntimeException("Blowfish encryption key not specified");
}
byte[] bytes = Hex.decodeHex(encryption_key.toCharArray());
_serializer = new BlowfishSerializer(new ListDelegateSerializer(), bytes);
} catch (org.apache.commons.codec.DecoderException ex) {
throw new RuntimeException("Blowfish encryption key invalid", ex);
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public void setSecretKey( String keyString ) throws CryptoKeyException {
try {
setSecretKey( Hex.decodeHex( keyString.toCharArray() ) );
} catch ( Exception e ) {
throw new CryptoKeyException( e );
}
}
代码示例来源:origin: signalapp/Signal-Server
private boolean isValidSignature(String prefix, String suffix, Mac mac) {
try {
byte[] ourSuffix = Util.truncate(getHmac(key, prefix.getBytes(), mac), 10);
byte[] theirSuffix = Hex.decodeHex(suffix.toCharArray());
return MessageDigest.isEqual(ourSuffix, theirSuffix);
} catch (DecoderException e) {
logger.warn("DirectoryCredentials", e);
return false;
}
}
代码示例来源:origin: commons-codec/commons-codec
private void checkDecodeHexCharArrayOddCharacters(final String data) {
try {
Hex.decodeHex(data);
fail("An exception wasn't thrown when trying to decode an odd number of characters");
} catch (final DecoderException e) {
// Expected exception
}
}
代码示例来源:origin: commons-codec/commons-codec
private void checkDecodeHexCharArrayOddCharacters(final char[] data) {
try {
Hex.decodeHex(data);
fail("An exception wasn't thrown when trying to decode an odd number of characters");
} catch (final DecoderException e) {
// Expected exception
}
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldReEncryptUsingNewKey() throws DecoderException, CryptoException {
String originalCipherText = "mvcX9yrQsM4iPgm1tDxN1A==";
String newCipherText = DESEncrypter.reEncryptUsingNewKey(decodeHex("269298bc31c44620"), decodeHex("02644c13cb892962"), originalCipherText);
assertThat(originalCipherText).isNotEqualTo(newCipherText);
DESCipherProvider newCipher = mock(DESCipherProvider.class);
when(newCipher.getKey()).thenReturn(decodeHex("02644c13cb892962"));
DESEncrypter newEncrypter = new DESEncrypter(newCipher);
assertThat(newEncrypter.decrypt(newCipherText)).isEqualTo("user-password!");
}
}
代码示例来源:origin: commons-codec/commons-codec
@Test
public void testDecodeHexCharArrayEmpty() throws DecoderException {
assertTrue(Arrays.equals(new byte[0], Hex.decodeHex(new char[0])));
}
代码示例来源:origin: commons-codec/commons-codec
@Test
public void testDecodeHexStringEmpty() throws DecoderException {
assertTrue(Arrays.equals(new byte[0], Hex.decodeHex("")));
}
代码示例来源:origin: gocd/gocd
@Before
public void setUp() throws Exception {
AESCipherProvider cipherProvider = mock(AESCipherProvider.class);
when(cipherProvider.getKey()).thenReturn(decodeHex("fdf500c4ec6e51172477145db6be63c5"));
aesEncrypter = new AESEncrypter(cipherProvider);
}
代码示例来源:origin: gocd/gocd
@Before
public void setUp() throws Exception {
DESCipherProvider cipherProvider = mock(DESCipherProvider.class);
when(cipherProvider.getKey()).thenReturn(decodeHex("269298bc31c44620"));
desEncrypter = new DESEncrypter(cipherProvider);
}
代码示例来源:origin: apache/nifi
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext validationContext) {
try {
Hex.decodeHex(input.toCharArray());
return new ValidationResult.Builder().valid(true).input(input).subject(subject).build();
} catch (final Exception e) {
return new ValidationResult.Builder().valid(false).explanation("Not a valid Hex String").input(input).subject(subject).build();
}
}
}
代码示例来源:origin: commons-codec/commons-codec
@Test
public void testByteToStringVariations() throws DecoderException {
final Base64 base64 = new Base64(0);
final byte[] b1 = StringUtils.getBytesUtf8("Hello World");
final byte[] b2 = new byte[0];
final byte[] b3 = null;
final byte[] b4 = Hex.decodeHex("2bf7cc2701fe4397b49ebeed5acc7090"); // for
// url-safe
// tests
assertEquals("byteToString Hello World", "SGVsbG8gV29ybGQ=", base64.encodeToString(b1));
assertEquals("byteToString static Hello World", "SGVsbG8gV29ybGQ=", Base64.encodeBase64String(b1));
assertEquals("byteToString \"\"", "", base64.encodeToString(b2));
assertEquals("byteToString static \"\"", "", Base64.encodeBase64String(b2));
assertEquals("byteToString null", null, base64.encodeToString(b3));
assertEquals("byteToString static null", null, Base64.encodeBase64String(b3));
assertEquals("byteToString UUID", "K/fMJwH+Q5e0nr7tWsxwkA==", base64.encodeToString(b4));
assertEquals("byteToString static UUID", "K/fMJwH+Q5e0nr7tWsxwkA==", Base64.encodeBase64String(b4));
assertEquals("byteToString static-url-safe UUID", "K_fMJwH-Q5e0nr7tWsxwkA",
Base64.encodeBase64URLSafeString(b4));
}
内容来源于网络,如有侵权,请联系作者删除!