Refine search
/** * Base64-decode the given byte array. * @param src the encoded byte array * @return the original byte array */ public static byte[] decode(byte[] src) { if (src.length == 0) { return src; } return Base64.getDecoder().decode(src); }
public byte[] getDataAsBytes() { if (dataAsBytes == null) { dataAsBytes = Base64.getDecoder().decode(data); } return dataAsBytes; }
public Image(String contentType, String data, String hash) { this.contentType = contentType; this.data = data; this.hash = hash; this.dataAsBytes = Base64.getDecoder().decode(data); }
/** * Base64-decode the given byte array. * @param src the encoded byte array * @return the original byte array */ public static byte[] decode(byte[] src) { if (src.length == 0) { return src; } return Base64.getDecoder().decode(src); }
@Override public Buffer binaryValue() { return value != null ? Buffer.buffer(Base64.getDecoder().decode((String) value)) : null; }
/** * Like {@link #getBinary(String)} but specifying a default value to return if there is no entry. * * @param key the key to lookup * @param def the default value to use if the entry is not present * @return the value or {@code def} if no entry present */ public byte[] getBinary(String key, byte[] def) { Objects.requireNonNull(key); Object val = map.get(key); return val != null || map.containsKey(key) ? (val == null ? null : Base64.getDecoder().decode((String)val)) : def; }
// decode the base64 encoded string byte[] decodedKey = Base64.getDecoder().decode(encodedKey); // rebuild key using SecretKeySpec SecretKey originalKey = new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES");
private String decodeBase64(String s) { try { return new String(Base64.getDecoder().decode(s), StandardCharsets.US_ASCII); } catch (IllegalArgumentException e) { return ""; } }
import java.util.Base64; byte[] bytes = "Hello, World!".getBytes("UTF-8"); String encoded = Base64.getEncoder().encodeToString(bytes); byte[] decoded = Base64.getDecoder().decode(encoded);
public static ScramCredential credentialFromString(String str) { Properties props = toProps(str); if (props.size() != 4 || !props.containsKey(SALT) || !props.containsKey(STORED_KEY) || !props.containsKey(SERVER_KEY) || !props.containsKey(ITERATIONS)) { throw new IllegalArgumentException("Credentials not valid: " + str); } byte[] salt = Base64.getDecoder().decode(props.getProperty(SALT)); byte[] storedKey = Base64.getDecoder().decode(props.getProperty(STORED_KEY)); byte[] serverKey = Base64.getDecoder().decode(props.getProperty(SERVER_KEY)); int iterations = Integer.parseInt(props.getProperty(ITERATIONS)); return new ScramCredential(salt, storedKey, serverKey, iterations); }
public static String decodeBase64ToString(String base64) { return new String(java.util.Base64.getDecoder().decode(base64.getBytes(UTF_8)), UTF_8); }
/** * @return the decoded base64 of the cookie or {@code null} if the value was not correctly encoded */ private @CheckForNull String decodeCookieBase64(@Nonnull String base64EncodedValue){ for (int j = 0; j < base64EncodedValue.length() % 4; j++) { base64EncodedValue = base64EncodedValue + "="; } try { // any charset should be fine but better safe than sorry byte[] decodedPlainValue = java.util.Base64.getDecoder().decode(base64EncodedValue.getBytes(StandardCharsets.UTF_8)); return new String(decodedPlainValue, StandardCharsets.UTF_8); } catch (IllegalArgumentException e) { return null; } }
byte[] message = "hello world".getBytes(StandardCharsets.UTF_8); String encoded = Base64.getEncoder().encodeToString(message); byte[] decoded = Base64.getDecoder().decode(encoded); System.out.println(encoded); System.out.println(new String(decoded, StandardCharsets.UTF_8));
public ClientFinalMessage(byte[] messageBytes) throws SaslException { String message = toMessage(messageBytes); Matcher matcher = PATTERN.matcher(message); if (!matcher.matches()) throw new SaslException("Invalid SCRAM client final message format: " + message); this.channelBinding = Base64.getDecoder().decode(matcher.group("channel")); this.nonce = matcher.group("nonce"); this.proof = Base64.getDecoder().decode(matcher.group("proof")); } public ClientFinalMessage(byte[] channelBinding, String nonce) {
public static String decryptUsingAES(SecretKey secretKey, String dataToDecrypt) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { Cipher aesCipher = Cipher.getInstance("AES"); aesCipher.init(Cipher.DECRYPT_MODE, secretKey); byte[] bytePlainText = aesCipher.doFinal(Base64.getDecoder().decode(dataToDecrypt)); return new String(bytePlainText); } }
@Override public byte[] deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { String text = p.getText(); try { return Base64.getDecoder().decode(text); } catch (IllegalArgumentException e) { throw new InvalidFormatException(p, "Expected a base64 encoded byte array", text, Instant.class); } } }
private static byte[] toByteArray(Object obj, Type type, String name) { if (obj instanceof byte[]) { return (byte[]) obj; } else if (obj instanceof String) { return Base64.getDecoder().decode((String) obj); } else { handleInvalidValue(name, type, obj); return null; } }
private static String decodeCredentials(String credentials) throws AuthenticationException { // The original basic auth RFC 2617 did not specify a character set. // Many clients, including the Presto CLI and JDBC driver, use ISO-8859-1. // RFC 7617 allows the server to specify UTF-8 as the character set during // the challenge, but this doesn't help as most clients pre-authenticate. try { return new String(Base64.getDecoder().decode(credentials), ISO_8859_1); } catch (IllegalArgumentException e) { throw new AuthenticationException("Invalid base64 encoded credentials"); } }
public static String decodeViewData(String data) { checkCondition(data.startsWith(VIEW_PREFIX), HIVE_INVALID_VIEW_DATA, "View data missing prefix: %s", data); checkCondition(data.endsWith(VIEW_SUFFIX), HIVE_INVALID_VIEW_DATA, "View data missing suffix: %s", data); data = data.substring(VIEW_PREFIX.length()); data = data.substring(0, data.length() - VIEW_SUFFIX.length()); return new String(Base64.getDecoder().decode(data), UTF_8); }
/** * Deserialize an object stored in a string. The String is assumed to be a base64 encoded string containing the bytes to actually * deserialize. * * @param str the encoded string. * @param clazz the thrift class we are expecting. * @param <T> The type of clazz * @return the decoded object */ public static <T> T deserializeFromString(String str, Class<T> clazz) { return deserialize(Base64.getDecoder().decode(str), clazz); }