本文整理匯總了Java中org.apache.commons.net.util.Base64.encodeBase64方法的典型用法代碼示例。如果您正苦於以下問題:Java Base64.encodeBase64方法的具體用法?Java Base64.encodeBase64怎麽用?Java Base64.encodeBase64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.net.util.Base64
的用法示例。
在下文中一共展示了Base64.encodeBase64方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getOAuthTokenPair
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
public static JSONObject getOAuthTokenPair(String backendHTTPURL, String backendHTTPSURL) throws Exception {
String AuthString = "Basic YWRtaW46YWRtaW4=";
RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, AuthString);
HttpResponse oAuthData = client.post(Constants.APIApplicationRegistration.API_APP_REGISTRATION_ENDPOINT,
Constants.APIApplicationRegistration.API_APP_REGISTRATION_PAYLOAD);
JSONObject jsonObj = new JSONObject(oAuthData.getData());
String clientId = jsonObj.get(Constants.OAUTH_CLIENT_ID).toString();
String clientSecret = jsonObj.get(Constants.OAUTH_CLIENT_SECRET).toString();
byte[] bytesEncoded = Base64.encodeBase64((clientId + ":" + clientSecret).getBytes());
String basicAuthString = "Basic " + new String(bytesEncoded);
//Initiate a RestClient to get OAuth token
client = new RestClient(backendHTTPSURL, Constants.APPLICATION_URL_ENCODED, basicAuthString);
oAuthData = client.post(Constants.APIApplicationRegistration.TOKEN_ENDPOINT,
Constants.APIApplicationRegistration.OAUTH_TOKEN_PAYLOAD);
jsonObj = new JSONObject(oAuthData.getData());
return jsonObj;
}
示例2: initTest
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
@BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP})
public void initTest() throws Exception {
super.init(userMode);
User currentUser = getAutomationContext().getContextTenant().getContextUser();
byte[] bytesEncoded = Base64
.encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes());
String encoded = new String(bytesEncoded);
String auth_string = "Basic " + encoded;
String anaytics_https_url = automationContext.getContextUrls().getWebAppURLHttps()
.replace("9443", String.valueOf(Constants.HTTPS_ANALYTICS_PORT))
.replace("/t/" + automationContext.getContextTenant().getDomain(), "") + "/";
this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
this.analyticsClient = new RestClient(anaytics_https_url, Constants.APPLICATION_JSON, auth_string);
if (this.userMode == TestUserMode.TENANT_ADMIN) {
HttpResponse response = client
.post(Constants.AndroidSenseEnrollment.ANALYTICS_ARTIFACTS_DEPLOYMENT_ENDPOINT, "");
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
}
}
示例3: createHttpStream
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
private HttpURLConnection createHttpStream()
throws IOException {
String apiUrl = joinUrlPath(
joinUrlPath(config.getNavigatorUrl(),
"api/v" + String.valueOf(config.getApiVersion())),
"metadata/plugin");
HttpURLConnection conn = openConnection(new URL(apiUrl));
conn.setRequestMethod("POST");
String userpass = config.getUsername() + ":" + config.getPassword();
String basicAuth = "Basic " + new String(Base64.encodeBase64(
userpass.getBytes()));
conn.addRequestProperty("Authorization", basicAuth);
conn.addRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
return conn;
}
示例4: getOAuthToken
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
public static String getOAuthToken(String backendHTTPURL, String backendHTTPSURL) throws Exception {
RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON);
HttpResponse oAuthData = client.post(Constants.DynamicClientAuthentication.REGISTRATION_ENDPOINT,
Constants.DynamicClientAuthentication.DYNAMIC_CLIENT_REGISTRATION_PAYLOAD);
JSONObject jsonObj = new JSONObject(oAuthData.getData());
String clientId = jsonObj.get(Constants.OAUTH_CLIENT_ID).toString();
String clientSecret = jsonObj.get(Constants.OAUTH_CLIENT_SECRET).toString();
byte[] bytesEncoded = Base64.encodeBase64((clientId + ":" + clientSecret).getBytes());
String basicAuthString = "Basic " + new String(bytesEncoded);
//Initiate a RestClient to get OAuth token
client = new RestClient(backendHTTPSURL, Constants.APPLICATION_URL_ENCODED, basicAuthString);
oAuthData = client.post(Constants.DynamicClientAuthentication.TOKEN_ENDPOINT,
Constants.DynamicClientAuthentication.OAUTH_TOKEN_PAYLOAD);
jsonObj = new JSONObject(oAuthData.getData());
return jsonObj.get(Constants.OAUTH_ACCESS_TOKEN).toString();
}
示例5: save
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
/**
*
* @param demographicNo
* @param obj
* @param providerNo
* @param facilityId
* @return Returns null if it already existed in the database.
* @throws Exception
*/
public RemoteIntegratedDataCopy save(Integer demographicNo, Object obj,String providerNo, Integer facilityId,String type) throws Exception{
if(obj == null){
throw new Exception("Can't save null");
}
if(type == null){
type = "";
}else{
type = "+"+type;
}
String dataType = obj.getClass().getName()+type;
String marshalledObject = ObjectMarshalUtil.marshalToString(obj);
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.reset();
byte[] digest = md.digest(marshalledObject.getBytes("UTF-8"));
String signature = new String(Base64.encodeBase64(digest), MiscUtils.DEFAULT_UTF8_ENCODING);
MiscUtils.getLogger().debug("demo :"+demographicNo+" dataType : "+dataType+" Signature: "+signature+" providerNo "+providerNo+" facilityId "+facilityId);
RemoteIntegratedDataCopy remoteIntegratedDataCopy = this.findByDemoTypeSignature(facilityId,demographicNo, dataType, signature);
if (remoteIntegratedDataCopy == null){
RemoteIntegratedDataCopy rid = new RemoteIntegratedDataCopy();
rid.setDemographicNo(demographicNo);
rid.setDataType(dataType);
rid.setData(marshalledObject);
rid.setSignature(signature);
rid.setProviderNo(providerNo);
rid.setFacilityId(facilityId);
this.persist(rid);
archiveDataCopyExceptThisOne(rid);//Set all other notes besides this one to archived.
return rid;
}
return null;
}
示例6: setContentDecoded
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
/**
* Sets the content of the description object metadata.
*
* @param content
* The decoded content
*/
public void setContentDecoded(String content) {
if (content != null) {
byte[] encoded = Base64.encodeBase64(content.getBytes());
this.content = new String(encoded);
}
}
示例7: init
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
protected void init(TestUserMode userMode) throws Exception {
automationContext = new AutomationContext(Constants.AUTOMATION_CONTEXT, userMode);
String tenantDomain = automationContext.getContextTenant().getDomain();
backendHTTPSURL = automationContext.getContextUrls().getWebAppURLHttps().replace("9443", String.valueOf(Constants
.HTTPS_GATEWAY_PORT)).replace("/t/" + tenantDomain , "");
backendHTTPURL = automationContext.getContextUrls().getWebAppURL().replace("9763", String.valueOf(Constants
.HTTP_GATEWAY_PORT)).replace("/t/" + tenantDomain , "");
User currentUser = getAutomationContext().getContextTenant().getContextUser();
byte[] bytesEncoded = Base64
.encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes());
String encoded = new String(bytesEncoded);
accessToken = OAuthUtil.getOAuthTokenPair(encoded, backendHTTPSURL, backendHTTPSURL, currentUser.getUserName(),
currentUser.getPassword());
accessTokenString = "Bearer " + accessToken;
}
示例8: createHttpConnection
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
private HttpURLConnection createHttpConnection(ClientConfig config, Set<String> entityIds)
throws IOException {
String navUrl = config.getNavigatorUrl();
String serverUrl = navUrl + (navUrl.endsWith("/") ? LINEAGE_EXPORT_API : "/" + LINEAGE_EXPORT_API);
String queryParamString = String.format(LINEAGE_EXPORT_API_QUERY_PARAMS,
URLEncoder.encode(direction, charset), // direction of lineage
URLEncoder.encode(length, charset), // length of lineage
URLEncoder.encode(lineageOptions, charset)); // Apply all filters
URL url = new URL(serverUrl + queryParamString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
String userpass = config.getUsername() + ":" + config.getPassword();
String basicAuth = "Basic " + new String(Base64.encodeBase64(
userpass.getBytes()));
conn.addRequestProperty("Authorization", basicAuth);
conn.addRequestProperty("Content-Type", "application/json");
conn.addRequestProperty("Accept", "application/json");
conn.setReadTimeout(0);
conn.setRequestMethod("POST");
// entityIds to pass in the request body
String postData = constructEntityIdsAsCSV(entityIds);
postData = "[" + postData + "]";
byte[] postDataBytes = postData.toString().getBytes("UTF-8");
conn.addRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length));
conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);
return conn;
}
示例9: calculateSignature
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
public String calculateSignature() {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
StringBuilder sigString = new StringBuilder();
sigString.append(this.name).append("|").append(this.getFactTable()).append("|").append(JsonUtil.writeValueAsString(this.model.getPartitionDesc())).append("|").append(JsonUtil.writeValueAsString(this.dimensions)).append("|").append(JsonUtil.writeValueAsString(this.measures)).append("|").append(JsonUtil.writeValueAsString(this.rowkey)).append("|").append(JsonUtil.writeValueAsString(this.hbaseMapping));
byte[] signature = md.digest(sigString.toString().getBytes());
return new String(Base64.encodeBase64(signature));
} catch (NoSuchAlgorithmException | JsonProcessingException e) {
throw new RuntimeException("Failed to calculate signature");
}
}
示例10: connect
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
private HttpResponse connect(String httpOperation, String url, String jsonPacket,
List<NameValuePair> queryParameters) throws URISyntaxException, IOException {
final String METHOD = "connect";
StringEntity input = null;
if(jsonPacket != null) {
input = new StringEntity(jsonPacket, StandardCharsets.UTF_8);
}
String encodedString = null;
if (!isQuickstart) {
byte[] encoding = Base64.encodeBase64(new String(authKey + ":"
+ authToken).getBytes());
encodedString = new String(encoding);
}
switch(httpOperation) {
case "post":
return casePostFromConnect(queryParameters, url, METHOD,input, encodedString);
case "put":
return casePutFromConnect(queryParameters, url, METHOD,input, encodedString);
case "get":
return caseGetFromConnect(queryParameters, url, METHOD,input, encodedString);
case "delete":
return caseDeleteFromConnect(queryParameters, url, METHOD,input, encodedString);
case "patch":
return casePatchFromConnect(queryParameters, url, METHOD,input, encodedString);
}
return null;
}
示例11: writeBase64String
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
private void writeBase64String(Writer writer, String str) throws IOException {
String tmp = new String(Base64.encodeBase64(str.getBytes()));
writeString(writer, tmp);
}
示例12: getBasicAuthHeader
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
private String getBasicAuthHeader() {
return "Basic " + new String(Base64.encodeBase64("username:password".getBytes()));
}
示例13: getAuthHeader
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
private String getAuthHeader(String username, String password) {
String auth = username + ":" + password;
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));
return "Basic " + new String(encodedAuth);
}
示例14: encodeIdentifier
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
/**
* Encode a byte[] identifier as a Base64-encoded string.
*
* @param identifier identifier to encode
* @return Base64-encoded string
*/
static String encodeIdentifier(byte[] identifier) {
return new String(Base64.encodeBase64(identifier),
Charset.defaultCharset());
}
示例15: encodeIdentifier
import org.apache.commons.net.util.Base64; //導入方法依賴的package包/類
/**
* Encode a byte[] identifier as a Base64-encoded string.
*
* @param identifier identifier to encode
* @return Base64-encoded string
*/
static String encodeIdentifier(byte[] identifier) {
return new String(Base64.encodeBase64(identifier));
}