本文整理了Java中com.sun.jersey.core.util.Base64.decode()
方法的一些代码示例,展示了Base64.decode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.decode()
方法的具体详情如下:
包路径:com.sun.jersey.core.util.Base64
类名称:Base64
方法名:decode
[英]Decodes a string containing Base64 data
[中]解码包含Base64数据的字符串
代码示例来源:origin: com.sun.jersey/jersey-bundle
/**
* Decodes a string containing Base64 data
*
* @param data the String to decode.
* @return Decoded Base64 array
*/
public static byte[] decode(String data) {
return decode(data.getBytes());
}
代码示例来源:origin: jersey/jersey-1.x
/**
* Decodes a string containing Base64 data
*
* @param data the String to decode.
* @return Decoded Base64 array
*/
public static byte[] decode(String data) {
return decode(data.getBytes());
}
代码示例来源:origin: Comcast/cmb
public ByteBuffer getBinaryValue() {
if (DataType.equals("Binary")) {
return ByteBuffer.wrap(Base64.decode(Value));
} else {
return ByteBuffer.wrap(Value.getBytes());
}
}
代码示例来源:origin: jvelo/mayocat-shop
protected Object deserialize(String serialized) throws IOException, ClassNotFoundException
{
byte[] data = Base64.decode(serialized);
ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(data));
Object object = objectInputStream.readObject();
objectInputStream.close();
return object;
}
代码示例来源:origin: com.netflix.dyno/dyno-core
/**
* Decompresses the given byte array and decodes with Base64 decoding
*
* @param compressed byte array input
* @return decompressed data in string format
* @throws IOException
*/
public static String decompressString(byte[] compressed) throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(compressed);
try (InputStream gis = new GZIPInputStream(is)) {
return new String(Base64.decode(IOUtils.toByteArray(gis)), StandardCharsets.UTF_8);
}
}
代码示例来源:origin: com.netflix.dyno/dyno-core
/**
* Given a Base64 encoded String, decompresses it.
*
* @param compressed Compressed String
* @return decompressed String
* @throws IOException
*/
public static String decompressFromBase64String(String compressed) throws IOException {
return decompressString(Base64.decode(compressed.getBytes(StandardCharsets.UTF_8)));
}
代码示例来源:origin: com.plausiblelabs.warwizard/warwizard-core
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
String auth = ((HttpServletRequest)request).getHeader("Authorization");
if (auth != null && auth.startsWith("Basic ")) {
String combined = new String(Base64.decode(auth.substring(credOffset)), Charsets.UTF_8);
Iterator<String> credentials = splitter.split(combined).iterator();
if (credentials.hasNext() && username.equals(credentials.next()) &&
credentials.hasNext() && password.equals(credentials.next())) {
chain.doFilter(request, response);
return;
}
}
HttpServletResponse resp = (HttpServletResponse)response;
resp.setHeader("WWW-Authenticate", "Basic realm=\"Admin\"" );
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
代码示例来源:origin: gary-rowe/multibit-merchant
/**
* Compute the HMAC signature for the given data and shared secret
*
* @param algorithm The algorithm to use (e.g. "HmacSHA512")
* @param data The data to sign
* @param sharedSecret The shared secret key to use for signing
*
* @return A base 64 encoded signature encoded as UTF-8
*/
public static byte[] computeSignature(String algorithm, byte[] data, byte[] sharedSecret) {
try {
SecretKey secretKey = new SecretKeySpec(Base64.decode(sharedSecret), algorithm);
Mac mac = Mac.getInstance(algorithm);
mac.init(secretKey);
mac.update(data);
return Base64.encode(mac.doFinal());
} catch (NoSuchAlgorithmException e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (InvalidKeyException e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
代码示例来源:origin: com.netflix.dyno/dyno-core
/**
* Determines if a String is compressed. The input String <b>must be Base64 encoded</b>.
* The java.util.zip GZip implementation does not expose the GZip header so it is difficult to determine
* if a string is compressed.
*
* @param input String
* @return true if the String is compressed or false otherwise
* @throws java.io.IOException if the byte array of String couldn't be read
*/
public static boolean isCompressed(String input) throws IOException {
return input != null && Base64.isBase64(input) &&
isCompressed(Base64.decode(input.getBytes(StandardCharsets.UTF_8)));
}
}
代码示例来源:origin: sdorra/scm-manager
/**
* Decodes the given value with the provided key.
*
* @param plainKey key which is used for decoding
* @param value encrypted value
*
* @return decrypted value
*/
public String decode(char[] plainKey, String value) {
String result = null;
try {
byte[] encodedInput = Base64.decode(value);
byte[] salt = new byte[SALT_LENGTH];
byte[] encoded = new byte[encodedInput.length - SALT_LENGTH];
System.arraycopy(encodedInput, 0, salt, 0, SALT_LENGTH);
System.arraycopy(encodedInput, SALT_LENGTH, encoded, 0,
encodedInput.length - SALT_LENGTH);
IvParameterSpec iv = new IvParameterSpec(salt);
SecretKey secretKey = buildSecretKey(plainKey);
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CIPHER_TYPE);
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, secretKey, iv);
byte[] decoded = cipher.doFinal(encoded);
result = new String(decoded, ENCODING);
} catch (IOException | GeneralSecurityException ex) {
throw new CipherException("could not decode string", ex);
}
return result;
}
代码示例来源:origin: sonia.scm/scm-core
/**
* Decodes the given value with the provided key.
*
* @param plainKey key which is used for decoding
* @param value encrypted value
*
* @return decrypted value
*/
public String decode(char[] plainKey, String value) {
String result = null;
try {
byte[] encodedInput = Base64.decode(value);
byte[] salt = new byte[SALT_LENGTH];
byte[] encoded = new byte[encodedInput.length - SALT_LENGTH];
System.arraycopy(encodedInput, 0, salt, 0, SALT_LENGTH);
System.arraycopy(encodedInput, SALT_LENGTH, encoded, 0,
encodedInput.length - SALT_LENGTH);
IvParameterSpec iv = new IvParameterSpec(salt);
SecretKey secretKey = buildSecretKey(plainKey);
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CIPHER_TYPE);
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, secretKey, iv);
byte[] decoded = cipher.doFinal(encoded);
result = new String(decoded, ENCODING);
} catch (IOException | GeneralSecurityException ex) {
throw new CipherException("could not decode string", ex);
}
return result;
}
代码示例来源:origin: sonia.scm/scm-core
/**
* Decode base64 of the basic authentication header. The method will use
* the charset provided by the {@link UserAgent}, if the
* {@link UserAgentParser} is not available the method will be fall back to
* ISO-8859-1.
*
* @param request http request
* @param authentication base64 encoded basic authentication string
*
* @return decoded basic authentication header
*
* @see <a href="http://goo.gl/tZEBS3">issue 627</a>
* @see <a href="http://goo.gl/NhbZ2F">Stackoverflow Basic Authentication</a>
*
* @throws UnsupportedEncodingException
*/
protected String decodeAuthenticationHeader(HttpServletRequest request,
String authentication)
throws UnsupportedEncodingException
{
Charset encoding = DEFAULT_ENCODING;
if (userAgentParser != null)
{
encoding = userAgentParser.parse(request).getBasicAuthenticationCharset();
}
return new String(Base64.decode(authentication), encoding);
}
代码示例来源:origin: sdorra/scm-manager
/**
* Decode base64 of the basic authentication header. The method will use
* the charset provided by the {@link UserAgent}, if the
* {@link UserAgentParser} is not available the method will be fall back to
* ISO-8859-1.
*
* @param request http request
* @param authentication base64 encoded basic authentication string
*
* @return decoded basic authentication header
*
* @see <a href="http://goo.gl/tZEBS3">issue 627</a>
* @see <a href="http://goo.gl/NhbZ2F">Stackoverflow Basic Authentication</a>
*
* @throws UnsupportedEncodingException
*/
protected String decodeAuthenticationHeader(HttpServletRequest request,
String authentication)
throws UnsupportedEncodingException
{
Charset encoding = DEFAULT_ENCODING;
if (userAgentParser != null)
{
encoding = userAgentParser.parse(request).getBasicAuthenticationCharset();
}
return new String(Base64.decode(authentication), encoding);
}
代码示例来源:origin: org.nuxeo.ecm.platform/nuxeo-platform-audit-core
value = SerializationUtils.deserialize(Base64.decode(node.binaryValue()));
break;
case ARRAY:
代码示例来源:origin: ff4j/ff4j
byte[] decodedBytes = Base64.decode(auth.replaceFirst("[B|b]asic ", ""));
String[] lap = new String(decodedBytes).split(":", 2);
if (lap == null || lap.length != 2) {
代码示例来源:origin: com.twitter.hraven/hraven-core
byte[] startRow = null;
if (startRowParam != null) {
startRow = Base64.decode(startRowParam);
代码示例来源:origin: twitter/hraven
byte[] startRow = null;
if (startRowParam != null) {
startRow = Base64.decode(startRowParam);
内容来源于网络,如有侵权,请联系作者删除!