本文整理了Java中java.util.Base64.getDecoder()
方法的一些代码示例,展示了Base64.getDecoder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.getDecoder()
方法的具体详情如下:
包路径:java.util.Base64
类名称:Base64
方法名:getDecoder
暂无
代码示例来源:origin: spring-projects/spring-framework
/**
* 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);
}
代码示例来源:origin: gocd/gocd
public byte[] getDataAsBytes() {
if (dataAsBytes == null) {
dataAsBytes = Base64.getDecoder().decode(data);
}
return dataAsBytes;
}
代码示例来源:origin: gocd/gocd
public Image(String contentType, String data, String hash) {
this.contentType = contentType;
this.data = data;
this.hash = hash;
this.dataAsBytes = Base64.getDecoder().decode(data);
}
代码示例来源:origin: org.springframework/spring-core
/**
* 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);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public Buffer binaryValue() {
return value != null ? Buffer.buffer(Base64.getDecoder().decode((String) value)) : null;
}
代码示例来源:origin: eclipse-vertx/vert.x
/**
* 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;
}
代码示例来源:origin: stackoverflow.com
// decode the base64 encoded string
byte[] decodedKey = Base64.getDecoder().decode(encodedKey);
// rebuild key using SecretKeySpec
SecretKey originalKey = new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES");
代码示例来源:origin: Graylog2/graylog2-server
private String decodeBase64(String s) {
try {
return new String(Base64.getDecoder().decode(s), StandardCharsets.US_ASCII);
} catch (IllegalArgumentException e) {
return "";
}
}
代码示例来源:origin: stackoverflow.com
import java.util.Base64;
byte[] bytes = "Hello, World!".getBytes("UTF-8");
String encoded = Base64.getEncoder().encodeToString(bytes);
byte[] decoded = Base64.getDecoder().decode(encoded);
代码示例来源:origin: apache/kafka
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);
}
代码示例来源:origin: apache/flink
public static String decodeBase64ToString(String base64) {
return new String(java.util.Base64.getDecoder().decode(base64.getBytes(UTF_8)), UTF_8);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* @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;
}
}
代码示例来源:origin: stackoverflow.com
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));
代码示例来源:origin: apache/kafka
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) {
代码示例来源:origin: gocd/gocd
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);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@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);
}
}
}
代码示例来源:origin: prestodb/presto
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;
}
}
代码示例来源:origin: prestodb/presto
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");
}
}
代码示例来源:origin: prestodb/presto
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);
}
代码示例来源:origin: apache/storm
/**
* 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);
}
内容来源于网络,如有侵权,请联系作者删除!