当前位置: 首页>>代码示例>>Java>>正文


Java Base64类代码示例

本文整理汇总了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;
		}
	}
 
开发者ID:nkeiter,项目名称:generic-dotCMS-plugin-code-examples,代码行数:21,代码来源:WebResource.java

示例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;
	}
}
 
开发者ID:nkeiter,项目名称:generic-dotCMS-plugin-code-examples,代码行数:19,代码来源:WebResource.java

示例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));
}
 
开发者ID:Appdynamics,项目名称:verizon-cloud-connector-extension,代码行数:23,代码来源:ConnectorLocator.java

示例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]);
}
 
开发者ID:s-case,项目名称:web-service-annotation-tool,代码行数:21,代码来源:GETAccountLoginHandler.java

示例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));
}
 
开发者ID:gausss,项目名称:MuSe,代码行数:19,代码来源:Encryption.java

示例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;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:14,代码来源:HTTPBasicAuth.java

示例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;
}
 
开发者ID:cfibmers,项目名称:open-Autoscaler,代码行数:12,代码来源:ConfigManager.java

示例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;
  }
 
开发者ID:cfibmers,项目名称:open-Autoscaler,代码行数:12,代码来源:ConfigManager.java

示例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;

}
 
开发者ID:CA-APM,项目名称:MAA--APM-Integration,代码行数:40,代码来源:SampleUtil.java

示例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);
    }
}
 
开发者ID:bazaarvoice,项目名称:dropwizard-caching-bundle,代码行数:11,代码来源:KeyUtils.java

示例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();
}
 
开发者ID:dkmsntua,项目名称:SociosApi,代码行数:11,代码来源:Utilities.java

示例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;
	}
}
 
开发者ID:dkmsntua,项目名称:SociosApi,代码行数:13,代码来源:Utilities.java

示例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;
}
 
开发者ID:Netflix,项目名称:dyno,代码行数:10,代码来源:ZipUtils.java

示例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();
}
 
开发者ID:Appdynamics,项目名称:verizon-cloud-connector-extension,代码行数:10,代码来源:RestClient.java

示例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());
    }


}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:38,代码来源:SecureAcceptAllGetTest.java


注:本文中的com.sun.jersey.core.util.Base64类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。