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


Java Base64.encode方法代码示例

本文整理汇总了Java中com.sun.jersey.core.util.Base64.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.encode方法的具体用法?Java Base64.encode怎么用?Java Base64.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.jersey.core.util.Base64的用法示例。


在下文中一共展示了Base64.encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: deleteArtifact

import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
/**
 * After deploying the artifact in the target repository we've to delete it from the origin
 * repository. This is done using the Nexus OSS REST API, simply calling a HTTP DELETE on the
 * resource.
 * 
 * @throws MojoExecutionException
 * @throws MojoFailureException
 */
private void deleteArtifact() throws MojoExecutionException, MojoFailureException {
	getLog().debug("Starting with deleting the artifact " + artifactId + " from repository " + stagingRepoID);

	String requestURL = targetNexus + NEXUS_CONTENT_PATH + stagingRepoID + DELI + groupId.replace(".", DELI) + DELI
			+ artifactId + DELI + version + DELI;
	getLog().debug("Request URL is: [" + requestURL + "]");

	if (mavenSession.getSettings().getServer(stagingRepoID) == null) {
		getLog().debug("Dont found credentials for " + stagingRepoID + " but found those:");
		for (Server server : mavenSession.getSettings().getServers()) {
			getLog().debug("######## SERVER ########");
			getLog().debug("Id: " + server.getId());
			getLog().debug("User: " + server.getUsername());
		}
		getLog().debug("Please verify your configuration and settinfs.xml");
		throw new MojoExecutionException("Not found server in settings.xml with id " + stagingRepoID);
	}

	String user = mavenSession.getSettings().getServer(stagingRepoID).getUsername();
	String password = mavenSession.getSettings().getServer(stagingRepoID).getPassword();
	String auth = new String(Base64.encode(user + ":" + password));

	Client client = Client.create();
	WebResource webResource = client.resource(requestURL);
	ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json")
			.accept("application/json").delete(ClientResponse.class);

	int statusCode = response.getStatus();

	getLog().debug("Status code is: " + statusCode);

	if (statusCode == 401) {
		throw new MojoExecutionException("Invalid Username or Password while accessing target repository.");
	} else if (statusCode != NEXUS_DELETE_SUCESS) {
		throw new MojoExecutionException("The artifact is not deleted - status code is: " + statusCode);
	}
	getLog().debug("Successfully deleted artifact " + artifactId + " from repository " + stagingRepoID);
}
 
开发者ID:hcguersoy,项目名称:nexus-maven-plugin,代码行数:47,代码来源:MoveNexusArtifact.java

示例8: should_create_an_app_with_correct_email__requires_authentication

import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
@Ignore
@Test
public void should_create_an_app_with_correct_email__requires_authentication() throws Exception {

    String accept = "application/vnd.heroku+json; version=3";
    String basic = "Basic " + new String(Base64.encode(emailaddress + ":" + apiKey), "ASCII");
    String request = "https://api.heroku.com/apps";

    APIReader apiReader = new APIReader(request);
    apiReader.setHeader("Accept", accept).setHeader("Authorization", basic);

    String response = apiReader.executePostUrl();

    assertThat(isSuccessfulAppCreationResponse(response), is(true));
}
 
开发者ID:neomatrix369,项目名称:RESTAPIUnifier,代码行数:16,代码来源:HerokuBehaviours.java

示例9: encode

import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
public String encode(String username, byte[] password) {
    try {

        final byte[] prefix = (username + ":").getBytes("UTF-8");
        final byte[] usernamePassword = new byte[prefix.length + password.length];

        System.arraycopy(prefix, 0, usernamePassword, 0, prefix.length);
        System.arraycopy(password, 0, usernamePassword, prefix.length, password.length);

        return "Basic " + new String(Base64.encode(usernamePassword), "ASCII");
    } catch (UnsupportedEncodingException ex) {
        // This should never occur
        throw new RuntimeException(ex);
    }
}
 
开发者ID:statsbiblioteket,项目名称:newspaper-batch-event-framework,代码行数:16,代码来源:JerseyContentsAttributeParsingEventTestWireMocked.java

示例10: executeGet

import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
private String executeGet (HttpGet get) throws IOException, ClientProtocolException, UnsupportedEncodingException
{
	String authorizationString = "Basic " + new String (Base64.encode ((customerId + ":" + password).getBytes ()), "US-ASCII");
	get.setHeader ("Authorization", authorizationString);
	HttpResponse response = client.execute (get);
	BufferedReader in = new BufferedReader (new InputStreamReader (response.getEntity ().getContent (), "UTF-8"));
	StringWriter writer = new StringWriter ();
	String line;
	while ( (line = in.readLine ()) != null )
	{
		writer.write (line);
	}
	String req = writer.toString ();
	return req;
}
 
开发者ID:bitsofproof,项目名称:btc1k,代码行数:16,代码来源:BopShopResource.java

示例11: build

import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
public static CacheRequestContext build(ContainerRequest request, Set<String> vary, boolean includeBody) {
    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-1");

        for (String header : vary) {
            List<String> headerValues = request.getRequestHeader(header);

            if (headerValues != null && headerValues.size() > 0) {
                digest.update(header.getBytes(Charsets.UTF_8));
                digest.update((byte) 0xFD);

                for (String value : headerValues) {
                    digest.update(value.getBytes(Charsets.UTF_8));
                    digest.update((byte) 0xFE);
                }

                digest.update((byte) 0xFF);
            }
        }

        if (includeBody) {
            byte[] requestBody = request.getEntity(byte[].class);

            if (requestBody == null) {
                requestBody = new byte[0];
            }

            if (requestBody.length > 0) {
                digest.update("Body".getBytes(Charsets.UTF_8));
                digest.update((byte) 0xFD);

                digest.update(requestBody);
                digest.update((byte) 0xFF);
            }

            request.setEntityInputStream(new ByteArrayInputStream(requestBody));
        }

        String hash = new String(Base64.encode(digest.digest()), Charsets.US_ASCII);
        return new CacheRequestContext(request.getMethod(), request.getRequestUri(), request.getRequestHeaders(), hash);
    } catch (NoSuchAlgorithmException ex) {
        // This error should not occur since SHA-1 must be included with every java distribution
        throw Throwables.propagate(ex);
    }
}
 
开发者ID:bazaarvoice,项目名称:dropwizard-caching-bundle,代码行数:46,代码来源:CacheRequestContext.java

示例12: modifyConnection

import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
@Override
protected void modifyConnection(HttpURLConnection connection) {
	byte[] authBytes = Base64.encode(API_KEY);
	String authString = new String(authBytes);
	connection.setRequestProperty("Authorization", "Basic " + authString);
}
 
开发者ID:tyiu,项目名称:EmailService,代码行数:7,代码来源:MailgunEmailServiceProvider.java

示例13: createAuthToken

import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
private String createAuthToken(String username, String password) {
	return new String(Base64.encode(username + ":" + password));
}
 
开发者ID:mnikliborc,项目名称:clicktrace,代码行数:4,代码来源:JiraRestClicktraceClient.java

示例14: authHeader

import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
public static String authHeader() {
    return "Basic " + new String(Base64.encode(Traitify.apiKey + ":x"));
}
 
开发者ID:traitify,项目名称:traitify-java,代码行数:4,代码来源:ApiModel.java

示例15: compressStringToBase64String

import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
/**
 * Encodes the given string with Base64 encoding and then GZIP compresses it. Returns
 * result as a Base64 encoded string.
 *
 * @param value input String
 * @return Base64 encoded compressed String
 * @throws IOException
 */
public static String compressStringToBase64String(String value) throws IOException {
    return new String(Base64.encode(compressString(value)), StandardCharsets.UTF_8);
}
 
开发者ID:Netflix,项目名称:dyno,代码行数:12,代码来源:ZipUtils.java


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