public AESSensitivePropertyProvider(byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException { this(key == null ? "" : Hex.toHexString(key)); }
private String base64Encode(byte[] input) { return Base64.toBase64String(input).replaceAll("=", ""); }
private byte[] decode(String encoded) throws DecoderException { if (this.encoding.equalsIgnoreCase("HEX")) { return Hex.decodeHex(encoded.toCharArray()); } else { return Base64.decode(encoded); } }
/** * Returns the key used to identify the provider implementation in {@code nifi.properties}. * * @return the key to persist in the sibling property */ @Override public String getIdentifierKey() { return IMPLEMENTATION_KEY + getKeySize(Hex.toHexString(key.getEncoded())); }
private static byte[] readPrivateKey(InputStream in) throws KeyException { String content; try { content = readContent(in); } catch (IOException e) { throw new KeyException("failed to read key input stream", e); } Matcher m = KEY_PATTERN.matcher(content); if (!m.find()) { throw new KeyException("could not find a PKCS #8 private key in input stream" + " (see http://netty.io/wiki/sslcontextbuilder-and-private-key.html for more information)"); } return Base64.decode(m.group(1)); }
/** * Returns a {@link SecretKey} formed from the hexadecimal key bytes (validity is checked). * * @param keyHex the key in hex form * @return the SecretKey */ public static SecretKey formKeyFromHex(String keyHex) throws KeyManagementException { if (keyIsValid(keyHex)) { return new SecretKeySpec(Hex.decode(keyHex), "AES"); } else { throw new KeyManagementException("The provided key material is not valid"); } }
private String encode(byte[] rawBytes) { if (this.encoding.equalsIgnoreCase("HEX")) { return Hex.encodeHexString(rawBytes); } else { return Base64.toBase64String(rawBytes); } }
@Test public void testDoFinalWithInput() { HMACSHA196 hmac = initHmac(); assertThat(Hex.toHexString(hmac.doFinal(PLAIN_TEXT)), is(EXPECTED_HMAC)); }
public static String digest(final String user, final String password) { return Base64.toBase64String(Hash.sha1digest( String.format("%s:%s", user, password).getBytes())); }
@Test public void testDoFinalWithInput() { HMACMD596 hmac = initHmac(); assertThat(Hex.toHexString(hmac.doFinal(PLAIN_TEXT)), is(EXPECTED_HMAC)); }
@Test public void testDoFinalWithInput() { HMACSHA2256 hmac = initHmac(); assertThat(Hex.toHexString(hmac.doFinal(PLAIN_TEXT)), is(EXPECTED_HMAC)); }
@Test public void testDoFinalWithInput() { HMACSHA1 hmac = initHmac(); assertThat(Hex.toHexString(hmac.doFinal(PLAIN_TEXT)), is(EXPECTED_HMAC)); }
@Test public void testDoFinalWithInput() { HMACMD5 hmac = initHmac(); assertThat(Hex.toHexString(hmac.doFinal(PLAIN_TEXT)), is(EXPECTED_HMAC)); }
@Test public void testDoFinalWithInput() { BaseMAC hmac = initHmac(); assertThat(Hex.toHexString(hmac.doFinal(PLAIN_TEXT)), is(EXPECTED_HMAC)); }
@Test public void testUpdateWithDoFinalWithResultBuffer() { HMACSHA196 hmac = initHmac(); byte[] resultBuf = new byte[12]; hmac.update(PLAIN_TEXT); hmac.doFinal(resultBuf, 0); assertThat(Hex.toHexString(resultBuf), is(EXPECTED_HMAC)); }
@Test public void testUpdateWithDoFinalWithResultBuffer() { HMACSHA1 hmac = initHmac(); byte[] resultBuf = new byte[20]; hmac.update(PLAIN_TEXT); hmac.doFinal(resultBuf, 0); assertThat(Hex.toHexString(resultBuf), is(EXPECTED_HMAC)); }
@Test public void testUpdateWithDoFinalWithResultBuffer() { HMACSHA2512 hmac = initHmac(); byte[] resultBuf = new byte[64]; hmac.update(PLAIN_TEXT); hmac.doFinal(resultBuf, 0); assertThat(Hex.toHexString(resultBuf), is(EXPECTED_HMAC)); }
@Test public void testUpdateWithDoFinal() { HMACMD5 hmac = initHmac(); hmac.update(PLAIN_TEXT); assertThat(Hex.toHexString(hmac.doFinal()), is(EXPECTED_HMAC)); }
@Test public void testUpdateWithDoFinal() { HMACMD596 hmac = initHmac(); hmac.update(PLAIN_TEXT); assertThat(Hex.toHexString(hmac.doFinal()), is(EXPECTED_HMAC)); }