本文整理汇总了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));
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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));
}
示例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;
}
示例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);
}
}
示例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);
}
示例13: createAuthToken
import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
private String createAuthToken(String username, String password) {
return new String(Base64.encode(username + ":" + password));
}
示例14: authHeader
import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
public static String authHeader() {
return "Basic " + new String(Base64.encode(Traitify.apiKey + ":x"));
}
示例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);
}