本文整理了Java中com.sun.jersey.core.util.Base64
类的一些代码示例,展示了Base64
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64
类的具体详情如下:
包路径:com.sun.jersey.core.util.Base64
类名称:Base64
[英]This class provides encode/decode for RFC 2045 Base64 as defined by RFC 2045, N. Freed and N. Borenstein. RFC 2045: Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies. Reference 1996
[中]此类为RFC 2045、N.Freed和N.Borenstein定义的RFC 2045 Base64提供编码/解码。RFC 2045:多用途Internet邮件扩展(MIME)第一部分:Internet邮件正文的格式。参考文献1996
代码示例来源:origin: signalapp/BitHub
private String getAuthorizationHeader(String user, String token) {
return "Basic " + new String(Base64.encode(user + ":" + token));
}
代码示例来源:origin: neo4j/neo4j
/**
* Extract the encoded username and password from a HTTP Authorization header value.
*/
public static String[] decode( String authorizationHeader )
{
String[] parts = authorizationHeader.trim().split( " " );
String tokenSegment = parts[parts.length - 1];
if ( tokenSegment.trim().length() == 0 )
{
return null;
}
String decoded = Base64.base64Decode( tokenSegment );
if ( decoded.length() < 1 )
{
return null;
}
String[] userAndPassword = decoded.split( ":", 2 );
if ( userAndPassword.length != 2 )
{
return null;
}
return userAndPassword;
}
}
代码示例来源: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: 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: jersey/jersey-1.x
public static boolean isArrayByteBase64(byte[] arrayOctect)
{
int length = arrayOctect.length;
if (length == 0)
{
// shouldn't a 0 length array be valid base64 data?
// return false;
return true;
}
for (int i=0; i < length; i++)
{
if ( !Base64.isBase64(arrayOctect[i]) )
return false;
}
return true;
}
代码示例来源:origin: com.sun.jersey/jersey-bundle
public static boolean isBase64(String isValidString)
{
return isArrayByteBase64(isValidString.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: com.sun.jersey/jersey-bundle
public static boolean isArrayByteBase64(byte[] arrayOctect)
{
int length = arrayOctect.length;
if (length == 0)
{
// shouldn't a 0 length array be valid base64 data?
// return false;
return true;
}
for (int i=0; i < length; i++)
{
if ( !Base64.isBase64(arrayOctect[i]) )
return false;
}
return true;
}
代码示例来源:origin: jersey/jersey-1.x
public static boolean isBase64(String isValidString)
{
return isArrayByteBase64(isValidString.getBytes());
}
代码示例来源:origin: twitter/ambrose
@Override
public PaginatedList<WorkflowSummary> getWorkflows(String cluster, Status status,
String username, int numResults, byte[] nextPageStart) throws IOException {
List<WorkflowSummary> workflowSummaryList = Lists.newArrayList();
PaginatedResult<Flow> flows =
flowQueueService.getPaginatedFlowsForStatus(cluster, convertStatus(status), numResults,
username, nextPageStart);
for (Flow flow : flows.getValues()) {
workflowSummaryList.add(toWorkflowSummary(flow));
}
PaginatedList<WorkflowSummary> paginatedList =
new PaginatedList<WorkflowSummary>(workflowSummaryList);
if (flows.getNextStartRow() != null) {
paginatedList.setNextPageStart(new String(Base64.encode(flows.getNextStartRow())));
}
return paginatedList;
}
代码示例来源:origin: Comcast/cmb
public ByteBuffer getBinaryValue() {
if (DataType.equals("Binary")) {
return ByteBuffer.wrap(Base64.decode(Value));
} else {
return ByteBuffer.wrap(Value.getBytes());
}
}
代码示例来源:origin: com.microsoft.windowsazure/microsoft-azure-api-core
@Override
public String unmarshal(String arg0) throws Exception {
return Base64.base64Decode(arg0);
}
}
代码示例来源:origin: ff4j/ff4j
/**
* Build Authorization header for final user.
* @param username target username
* @param password target password
* @return target header
*/
public static String buildAuthorization4UserName(String username, String password) {
return " Basic " + new String(Base64.encode(username + ":" + password));
}
代码示例来源: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.microsoft.azure/azure-core
@Override
public String unmarshal(String arg0) throws Exception {
return Base64.base64Decode(arg0);
}
}
代码示例来源:origin: com.sun.jersey/jersey-bundle
/**
* Encodes hex octets of a UTF-8 encoded String into Base64
*
* @param data the String to encode.
* @return Encoded Base64 array
*/
public static byte[] encode(String data) {
return encode(data.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: org.opendaylight.aaa/aaa-authn-basic
private static String[] extractCredentialArray(final String authHeader) {
return new String(Base64.base64Decode(authHeader.substring(BASIC_PREFIX.length())))
.split(AUTH_SEP);
}
代码示例来源:origin: jersey/jersey-1.x
/**
* Encodes hex octets of a UTF-8 encoded String into Base64
*
* @param data the String to encode.
* @return Encoded Base64 array
*/
public static byte[] encode(String data) {
return encode(data.getBytes());
}
内容来源于网络,如有侵权,请联系作者删除!