本文整理汇总了Java中com.sun.jersey.core.util.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于com.sun.jersey.core.util包,在下文中一共展示了Base64类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticateUserFromBasicAuth
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
private User authenticateUserFromBasicAuth(Map<String, String> paramsMap, HttpServletRequest request) throws SecurityException {
// Extract authentication credentials
String authentication = request.getHeader(ContainerRequest.AUTHORIZATION);
if(UtilMethods.isSet(authentication) && authentication.startsWith("Basic ")) {
authentication = authentication.substring("Basic ".length());
String[] values = new String(Base64.base64Decode(authentication)).split(":");
if (values.length < 2) {
// "Invalid syntax for username and password"
throw new SecurityException("Invalid syntax for username and password", Response.Status.BAD_REQUEST);
}
String username = values[0];
String password = values[1];
return authenticateUser(username, password, request);
} else {
return null;
}
}
示例2: authenticateUserFromHeaderAuth
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
private User authenticateUserFromHeaderAuth(Map<String, String> paramsMap, HttpServletRequest request) throws SecurityException {
// Extract authentication credentials
String authentication = request.getHeader("DOTAUTH");
if(UtilMethods.isSet(authentication)) {
String[] values = new String(Base64.base64Decode(authentication)).split(":");
if (values.length < 2) {
// "Invalid syntax for username and password"
throw new SecurityException("Invalid syntax for username and password", Response.Status.BAD_REQUEST);
}
String username = values[0];
String password = values[1];
return authenticateUser(username, password, request);
} else {
return null;
}
}
示例3: getUniqueId
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
private String getUniqueId(String accessKey, String secretKey) {
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("SHA");
} catch (NoSuchAlgorithmException e) {
LOG.log(Level.WARNING, "Algorithm not found", e);
throw new NoAlgoException("Algorithm not found", e);
}
digest.update(secretKey.getBytes());
byte[] hash = digest.digest("Secret Key".getBytes());
byte[] bytes = accessKey.getBytes();
byte[] finalBytes = new byte[bytes.length + hash.length];
for (int i = 0; i < bytes.length; i++) {
finalBytes[i] = bytes[i];
}
for (int i = 0; i < hash.length; i++) {
finalBytes[bytes.length + i] = hash[i];
}
return new String(Base64.encode(finalBytes));
}
示例4: decodeAuthorizationHeader
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
public void decodeAuthorizationHeader()
{
//check if this request has basic authentication
if( !authHeader.contains("Basic "))
{
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
authHeader = authHeader.substring("Basic ".length());
String[] decodedHeader;
decodedHeader = Base64.base64Decode(authHeader).split(":");
if( decodedHeader == null)
{
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
oAccount.setUsername(decodedHeader[0]);
oAccount.setPassword(decodedHeader[1]);
}
示例5: hashShaSalted
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
public static String hashShaSalted(String component, String salt) {
// Combine component and salt
String token = component + salt;
// Hash token with SHA-256
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-256");
md.update(token.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
LOG.warn("UTF-8 Encoding not supported.");
} catch (NoSuchAlgorithmException e1) {
LOG.warn("SHA-256 algorithm not found.");
}
byte[] digest = md.digest();
return new String(Base64.encode(digest));
}
示例6: parseAuthorization
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
private String[] parseAuthorization(String authorization) {
String parts[] = authorization.split(" ");
if (parts.length == 2 && parts[0].equalsIgnoreCase("Basic")) {
String userPass = Base64.base64Decode(parts[1]);
int p = userPass.indexOf(":");
if (p != -1) {
return new String[] { userPass.substring(0, p),
userPass.substring(p + 1) };
}
}
return null;
}
示例7: getInternalAuthToken
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
public static String getInternalAuthToken(){
String internalAuthUserName = ConfigManager.get("internalAuthUsername");
String internalAuthPassword = ConfigManager.get("internalAuthPassword");
try {
byte[] decryptSecret = Base64.encode(internalAuthUserName + ":" + internalAuthPassword);
return new String(decryptSecret,"UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error("Fail to encrypt for " + internalAuthUserName + ":" + internalAuthPassword + " with exception " + e.getMessage());
}
return null;
}
示例8: getInternalAuthToken
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
public static String getInternalAuthToken(){
String internalAuthUserName = ConfigManager.get("internalAuthUsername");
String internalAuthPassword = ConfigManager.get("internalAuthPassword");
try {
byte[] authToken = Base64.encode(internalAuthUserName + ":" + internalAuthPassword);
return new String(authToken,"UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error("Fail to encrypt for " + internalAuthUserName + ":" + internalAuthPassword + " with exception " + e.getMessage());
}
return null;
}
示例9: login
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
public static HashMap login (String username, String pwd, String org, String targeturl, boolean debug) {
// System.out.println("IN AdminLogin.login");
String headerOrg = "Basic " + Base64.encodeBase64String(org.getBytes());
targeturl = targeturl + "/ess/security/v1/token";
String params = "username=" + username + "&password=" + pwd + "&grant_type=PASSWORD";
//if (debug) {
System.out.println("SampleUtil:: targeturl..." + targeturl);
System.out.println("SampleUtil:: params..." + params);
System.out.println("SampleUtil:: headerOrg..." + headerOrg);
//}
int httpStatus = 0;
String respText = "";
HashMap hash = new HashMap();
Client client = new Client();
WebResource wr = client.resource(targeturl);
ClientResponse response = wr.accept("application/json")
.header("Content-type", "application/x-www-form-urlencoded")
.header("Authorization", headerOrg)
.post(ClientResponse.class, params);
httpStatus = response.getStatus();
respText = response.getEntity(String.class);
hash.put("HTTP_STATUS", new Integer(httpStatus));
hash.put("RESP_TEXT", respText);
//if (debug) {
System.out.println("SampleUtil:: httpStatus..." + httpStatus);
System.out.println("SampleUtil:: response.getEntity..." + respText);
//}
return hash;
}
示例10: generateKeyHash
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
private static byte[] generateKeyHash(byte[] keyBytes) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-1");
byte[] hashBytes = digest.digest(keyBytes);
return Base64.encode(hashBytes);
} catch (NoSuchAlgorithmException ex) {
// SHA-1 is included with every java distro, so this exception should not occur
throw Throwables.propagate(ex);
}
}
示例11: computeSignature
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
public static String computeSignature(String baseString, String keyString) throws GeneralSecurityException, UnsupportedEncodingException {
SecretKey secretKey;
byte[] keyBytes = keyString.getBytes();
secretKey = new SecretKeySpec(keyBytes, "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(secretKey);
byte[] text = baseString.getBytes();
byte[] foo = mac.doFinal(text);
return new String(Base64.encode(foo)).trim();
}
示例12: encodeKeys
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
public static String encodeKeys(String consumerKey, String consumerSecret) {
try {
String encodedConsumerKey = URLEncoder.encode(consumerKey, SociosConstants.UTF8);
String encodedConsumerSecret = URLEncoder.encode(consumerSecret, SociosConstants.UTF8);
String fullKey = encodedConsumerKey + ":" + encodedConsumerSecret;
String encodedBytes = new String(Base64.encode(fullKey.getBytes()));
return encodedBytes;
}
catch (UnsupportedEncodingException exc) {
return null;
}
}
示例13: compressString
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
public static byte[] compressString(String value) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(value.length());
GZIPOutputStream gos = new GZIPOutputStream(baos);
gos.write(Base64.encode(value.getBytes(StandardCharsets.UTF_8)));
gos.close();
byte[] compressed = baos.toByteArray();
baos.close();
return compressed;
}
示例14: sign
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
private String sign(ClientRequest request, MultivaluedMap<String, Object> headers) throws IllegalStateException, UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
StringBuilder stringToSign = new StringBuilder().append(getVerb(request)).append(getContentType(headers)).append(getDate(headers)).append(getCanonicalizedHeaders(headers)).append(getCanonicalizedResource(request));
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(getSecretKey().getBytes("UTF-8"), "HmacSHA256"));
byte[] digest = mac.doFinal(stringToSign.toString().getBytes("UTF-8"));
return new String(Base64.encode(digest)).trim();
}
示例15: init
import com.sun.jersey.core.util.Base64; //导入依赖的package包/类
@BeforeClass
public static void init() throws Exception {
// setup server 1, will use first keystore/truststore with client auth
TEST_PORT = new Random().nextInt(1000) + 4000;
TEST_SERVICE_URI = "https://127.0.0.1:" + TEST_PORT + "/";
// jks format
byte[] sampleTruststore1 = Base64.decode(SecureGetTest.TEST_TS1);
byte[] sampleKeystore1 = Base64.decode(SecureGetTest.TEST_KS1);
TEST_FILE_KS = File.createTempFile("SecureAcceptAllGetTest", ".keystore");
TEST_FILE_TS = File.createTempFile("SecureAcceptAllGetTest", ".truststore");
FileOutputStream keystoreFileOut = new FileOutputStream(TEST_FILE_KS);
try {
keystoreFileOut.write(sampleKeystore1);
} finally {
keystoreFileOut.close();
}
FileOutputStream truststoreFileOut = new FileOutputStream(TEST_FILE_TS);
try {
truststoreFileOut.write(sampleTruststore1);
} finally {
truststoreFileOut.close();
}
try{
TEST_SERVER = new SimpleSSLTestServer(TEST_FILE_TS, SecureGetTest.PASSWORD, TEST_FILE_KS, SecureGetTest.PASSWORD, TEST_PORT, false);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}