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


Java Base64.encodeBase64String方法代码示例

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


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

示例1: SignMessage

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
public static boolean SignMessage(String ellieSignature, String message, String secret) {
    try {
        Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
        SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
        sha256_HMAC.init(secret_key);

        String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(message.getBytes()));
        System.out.println(hash);

        if(ellieSignature == hash){
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        System.out.println("Error");
    }
    return true;
}
 
开发者ID:EllieMae,项目名称:api-webhook-sample-application,代码行数:20,代码来源:SignatureUtility.java

示例2: get

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
public Document get(String url) throws Exception{
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    String user = api.getUser();String password = api.getPassword();
    String authStr = user + ":" + password;
    String authEncoded = Base64.encodeBase64String(authStr.getBytes());
    con.setRequestMethod("GET");
    con.setRequestProperty("Authorization", "Basic " + authEncoded);
    con.setDoOutput(true);
    DocumentBuilderFactory factoryBuilder = DocumentBuilderFactory.newInstance();
    factoryBuilder.setIgnoringComments(true);
    factoryBuilder.setIgnoringElementContentWhitespace(true);
    DocumentBuilder d = factoryBuilder.newDocumentBuilder();
    Document document = d.parse(con.getInputStream());
    return document;
}
 
开发者ID:CodedByYou,项目名称:MAL-,代码行数:17,代码来源:MalGet.java

示例3: byteEmptyWithServiceResponseAsync

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * Get '' as byte array.
 *
 * @throws IllegalArgumentException thrown if parameters fail the validation
 * @return the {@link ServiceResponse} object if successful.
 */
public Observable<ServiceResponse<Void>> byteEmptyWithServiceResponseAsync() {
    final byte[] byteQuery = "".getBytes();
    String byteQueryConverted = Base64.encodeBase64String(byteQuery);
    return service.byteEmpty(byteQueryConverted)
        .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
            @Override
            public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
                try {
                    ServiceResponse<Void> clientResponse = byteEmptyDelegate(response);
                    return Observable.just(clientResponse);
                } catch (Throwable t) {
                    return Observable.error(t);
                }
            }
        });
}
 
开发者ID:Azure,项目名称:autorest.java,代码行数:23,代码来源:QueriesImpl.java

示例4: testAuthenticateWithException

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
@Test
public void testAuthenticateWithException() throws Exception {
    exception = true;
    platformService.exceptionOnGetControllerSettings = new APPlatformException(
            "failed");
    Mockito.when(session.getAttribute(Matchers.eq("loggedInUserId")))
            .thenReturn(null);

    String credentials = "user1:password1";
    String credentialsEncoded = Base64
            .encodeBase64String(credentials.getBytes());

    Mockito.when(req.getHeader(Matchers.eq("Authorization")))
            .thenReturn("Basic " + credentialsEncoded);

    // And go!
    filter.doFilter(req, resp, chain);

    // Check whether request has been forwarded
    Mockito.verify(resp).setStatus(Matchers.eq(401));
    Mockito.verify(resp).setHeader(Matchers.eq("WWW-Authenticate"),
            Matchers.startsWith("Basic "));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:AuthorizationFilterTest.java

示例5: encryptCbcTemp

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
public static String encryptCbcTemp(String content, String encryptKey)
		throws EncryptException
{
	if (StringUtils.isEmpty(content) || StringUtils.isEmpty(encryptKey))
	{
		return null;
	}
	
	// 因为加密key必须为16位
	if(encryptKey.length() > 16)
	{
		encryptKey = encryptKey.substring(0, 16);
	}
	else
	{
		int padLength = 16-encryptKey.length();
		
		for(int i = 0; i < padLength ;i++)
		{
			encryptKey += '0';
		}
	}
	
	try
	{
		IvParameterSpec zeroIv = new IvParameterSpec(VIPARA.getBytes());
		SecretKeySpec key = new SecretKeySpec(encryptKey.getBytes(), "AES");
		Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
		cipher.init(Cipher.ENCRYPT_MODE, key, zeroIv);
		byte[] encryptedData = cipher.doFinal(content.getBytes("utf-8"));

		return Base64.encodeBase64String(encryptedData);
	}
	catch (Exception e)
	{
		throw new EncryptException("Failed to encrypt for content: "
				+ content + ", encrypt key: " + encryptKey, e);
	}

}
 
开发者ID:marlonwang,项目名称:raven,代码行数:41,代码来源:AESUtils.java

示例6: testbrokenLink

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
@Test
public void testbrokenLink() throws IOException, URISyntaxException {

    JSONObject object = new JSONObject();
    object.put("key", "sprSCKKWf8xUeXxEo6Bv0lE1sSjWRDkO");
    object.put("marketName", "eoemarket");
    object.put("count", 1);
    JSONArray data = new JSONArray();
    JSONObject o = new JSONObject();
    o.put("id", -1);
    o.put("link", "http://testsssssss");
    o.put("statusCode", 404);
    data.add(o);
    object.put("data", data);

    Reader input = new StringReader(object.toJSONString());
    byte[] binaryData = IOUtils.toByteArray(input, "UTF-8");
    String encodeBase64 = Base64.encodeBase64String(binaryData);

    String url = "http://localhost:8080/sjk-market/market/brokenLink.d";
    url = "http://app-t.sjk.ijinshan.com/market/brokenLink.d";
    URIBuilder builder = new URIBuilder(url);
    builder.setParameter("c", encodeBase64);
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(builder.build());
    HttpResponse response = httpclient.execute(httpPost);
    logger.debug("URI: {} , {}", url, response.getStatusLine());

    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    // be convinient to debug
    String rspJSON = IOUtils.toString(is, "UTF-8");
    System.out.println(rspJSON);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:35,代码来源:ControllerTest.java

示例7: compress

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
public static String compress(String stringToCompress) throws UnsupportedEncodingException
{
    byte[] compressedData = new byte[1024];
    byte[] stringAsBytes = stringToCompress.getBytes("UTF-8");

    Deflater compressor = new Deflater();
    compressor.setInput(stringAsBytes);
    compressor.finish();
    int compressedDataLength = compressor.deflate(compressedData);

    byte[] bytes = Arrays.copyOf(compressedData, compressedDataLength);
    return Base64.encodeBase64String(bytes);
}
 
开发者ID:tmobile,项目名称:keybiner,代码行数:14,代码来源:Compression.java

示例8: testCreateInstanceUserData

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
@Test
public void testCreateInstanceUserData() throws Exception {
    String userData = "line1\nline2\n";
    String userDataBase64 = Base64.encodeBase64String(userData.getBytes());
    File myFile = createUserDataFile(userData);
    try {
        URL fileUrl = myFile.toURI().toURL();
        parameters.put(PropertyHandler.USERDATA_URL, new Setting(
                PropertyHandler.USERDATA_URL, fileUrl.toString()));
        ec2mock.createRunInstancesResult("instance2");
        ec2mock.createDescribeImagesResult("image1");
        ec2mock.createDescribeSubnetsResult("subnet-a77430d0");
        ec2mock.createDescribeSecurityGroupResult("subnet-a77430d0",
                "security_group1,security_group2");
        ec2mock.createDescribeInstancesResult("instance1", "ok", "1.2.3.4");
        Image image = ec2comm.resolveAMI("image1");

        ec2comm.createInstance(image);
        String result = ph.getAWSInstanceId();
        assertEquals("instance2", result);
        ArgumentCaptor<RunInstancesRequest> arg1 = ArgumentCaptor
                .forClass(RunInstancesRequest.class);
        verify(ec2).runInstances(arg1.capture());
        RunInstancesRequest rir = arg1.getValue();
        assertEquals(userDataBase64, rir.getUserData());
    } finally {
        myFile.delete();
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:30,代码来源:EC2CommunicationTest.java

示例9: main

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
public static void main(String[] args) throws UnsupportedEncodingException {
	String encodeString = URLEncoder.encode("何剑","UTF-8");
	System.out.println("encode : " + encodeString);
	System.out.println("decode : " + URLDecoder.decode(encodeString, "UTF-8"));
	encodeString = Base64.encodeBase64String("何剑".getBytes());
	System.out.println(encodeString);
	System.out.println(new String(Base64.decodeBase64(encodeString),"UTF-8"));
	
	String str = "aHR0cDovL3BtZi5jaGV4aWFuZy5jb20vdGVzdC9hdXRoLmh0bQ====";
	str = str.substring(0, str.length() - 2);
	System.out.println(new String(Base64.decodeBase64(str),"UTF-8"));
	
}
 
开发者ID:tojaoomy,项目名称:private-WeChat,代码行数:14,代码来源:AuthorizationController.java

示例10: testbrokenLink

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
@Test
public void testbrokenLink() throws IOException, URISyntaxException {

    JSONObject object = new JSONObject();
    object.put("key", "sprSCKKWf8xUeXxEo6Bv0lE1sSjWRDkO");
    object.put("marketName", "eoemarket");
    object.put("count", 1);
    JSONArray data = new JSONArray();
    JSONObject o = new JSONObject();
    o.put("id", -1);
    o.put("link", "http://testsssssss");
    o.put("statusCode", 404);
    data.add(o);
    object.put("data", data);

    String test = "eyJjb3VudCI6IDEwLCAibWFya2V0TmFtZSI6ICJBcHBDaGluYSIsICJkYXRhIjogW3sibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmdvb2dsZS5hbmRyb2lkLmFwcHMubWFwcyIsICJpZCI6IDEsICJzdGF0dXNDb2RlIjogNDA0fSwgeyJsaW5rIjogImh0dHA6Ly93d3cuYXBwY2hpbmEuY29tL2FwcC9jb20ud2VhdGhlci5XZWF0aGVyIiwgImlkIjogMiwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5zdHlsZW0ud2FsbHBhcGVycyIsICJpZCI6IDQsICJzdGF0dXNDb2RlIjogNDA0fSwgeyJsaW5rIjogImh0dHA6Ly93d3cuYXBwY2hpbmEuY29tL2FwcC9jb20uc2hhemFtLmVuY29yZS5hbmRyb2lkIiwgImlkIjogNSwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5yaW5nZHJvaWQiLCAiaWQiOiA2LCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLnAxLmNob21wc21zIiwgImlkIjogNywgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5oYW5kY2VudC5uZXh0c21zIiwgImlkIjogOCwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5mYWNlYm9vay5rYXRhbmEiLCAiaWQiOiA5LCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmNvZGUuaS5tdXNpYyIsICJpZCI6IDEwLCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmJpZ2d1LnNob3BzYXZ2eSIsICJpZCI6IDExLCAic3RhdHVzQ29kZSI6IDQwNH1dLCAia2V5IjogImpqRzhMa0MzTUh5RjlYY3NWS2g2Rkh4bXRMQ05ZdE14In0=";
    Reader input = new StringReader(object.toJSONString());
    byte[] binaryData = IOUtils.toByteArray(input, "UTF-8");
    String encodeBase64 = Base64.encodeBase64String(binaryData);
    System.out.println(encodeBase64);

    String url = "http://localhost:9080/sjk-market-admin/market/brokenLink.d";
    url = "http://app.sjk.ijinshan.com/market/brokenLink.d";
    URIBuilder builder = new URIBuilder(url);
    builder.setParameter("c", test);
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(builder.build());
    HttpResponse response = httpclient.execute(httpPost);
    logger.debug("URI: {} , {}", url, response.getStatusLine());

    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    // be convinient to debug
    String rspJSON = IOUtils.toString(is, "UTF-8");
    System.out.println(rspJSON);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:37,代码来源:ControllerTest.java

示例11: encryptPassword

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
/**
 * Returns encrypted version of given password like algorithm like in
 * WS-UsernameToken
 * 
 * @throws NoSuchAlgorithmException
 */
public String encryptPassword() throws NoSuchAlgorithmException {
	String nonce = getNonce();
	String timestamp = getUTCTime();

	String beforeEncryption = nonce + timestamp + password;

	byte[] encryptedRaw;
	encryptedRaw = sha1(beforeEncryption);
	String encoded = Base64.encodeBase64String(encryptedRaw);
	return encoded;
}
 
开发者ID:D2Edev,项目名称:onvifjava,代码行数:18,代码来源:OnvifDevice.java

示例12: generateEncodedKey

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
public String generateEncodedKey()
  {
try
{
   	return Base64.encodeBase64String(generateKeyData());
}
catch(Throwable e)
{
	fail("Unexpected exception: " + e.getMessage());
	return null;
}
  }
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:13,代码来源:KeyStoreTests.java

示例13: getEncoded

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
String getEncoded(String val) {
    return Base64.encodeBase64String(val.getBytes());
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:4,代码来源:SettingsUI.java

示例14: makeDocument

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
@Override
public void makeDocument(byte[] httpData) throws Exception {
       String t = context.statistics.start(EngineStatistics.GENERATE_DOM);

       try {
       	String stringData = "";
       	
       	if (httpData == null || httpData.length == 0) {
       		// nothing to do
       	}
       	else if (dataEncoding == HTTP_DATA_ENCODING_STRING) {
       		String charset = dataStringCharset;
       		
       		if (StringUtils.isBlank(charset)) {
       			charset  = ((HttpConnector) parent).getCharset();
       			Engine.logBeans.debug("(HttpTransaction) 'HTTP string charset' is blank, use detected charset: " + charset);
       		}
       		
           	if (charset == null) {
           		charset = "ascii";
           		Engine.logBeans.info("(HttpTransaction) No valid charset defined, use basic charset: " + charset);
           	}
           	try {
           		stringData = new String(httpData, charset);
           	} catch (UnsupportedEncodingException e) {
           		Engine.logBeans.warn("(HttpTransaction) Unsupported Encoding to decode the response, use ascii instead",  e);
           		stringData = new String(httpData, "ascii");
           	}
       	}
       	else if (dataEncoding == HTTP_DATA_ENCODING_BASE64) {
       		stringData = Base64.encodeBase64String(httpData);
       	}
       	else {
       		throw new IllegalArgumentException("Unknown data encoding: " + dataEncoding);
       	}
   		
       	Node child = responseInCDATA ?
       		context.outputDocument.createCDATASection(stringData) // remove TextCodec.UTF8Encode for #453
       		: context.outputDocument.createTextNode(stringData);
       	
       	Element outputDocumentRootElement = context.outputDocument.getDocumentElement();
       	outputDocumentRootElement.appendChild(child);
       }
       finally {
   		context.statistics.stop(t);
       }
   }
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:48,代码来源:HttpTransaction.java

示例15: base64ClientIdSecret

import org.apache.commons.codec.binary.Base64; //导入方法依赖的package包/类
private String base64ClientIdSecret() {
    String clientIdSecret = new StringJoiner(":")
            .add(oAuth2ClientProperties.getClientId())
            .add(oAuth2ClientProperties.getClientSecret()).toString();
    return Base64.encodeBase64String(clientIdSecret.getBytes());
}
 
开发者ID:SopraSteriaGroup,项目名称:initiatives_backend_auth,代码行数:7,代码来源:TokenService.java


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