當前位置: 首頁>>代碼示例>>Java>>正文


Java Base64.decode方法代碼示例

本文整理匯總了Java中org.apache.commons.codec.binary.Base64.decode方法的典型用法代碼示例。如果您正苦於以下問題:Java Base64.decode方法的具體用法?Java Base64.decode怎麽用?Java Base64.decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.codec.binary.Base64的用法示例。


在下文中一共展示了Base64.decode方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testEncode

import org.apache.commons.codec.binary.Base64; //導入方法依賴的package包/類
@Test
public void testEncode(){
    String message = "abcd";
    byte[] b=message.getBytes();
    Base64 base64=new Base64();
    byte[] b2 = base64.encode(b);
    String s=new String(b2);
    System.out.println(s);

    byte[] b3 = s.getBytes();
    byte[] b4 = base64.decode(b3);
    String s2=new String(b4);
    System.out.println(s2);

    Assert.assertTrue( message.equals(s2) );
}
 
開發者ID:kevin-xu-158,項目名稱:JavaNRPC,代碼行數:17,代碼來源:EtcdClientTest.java

示例2: verifyUserSig

import org.apache.commons.codec.binary.Base64; //導入方法依賴的package包/類
@Override
public boolean verifyUserSig(String identifier, String sig)throws QCloudException {
	try {
		Security.addProvider(new BouncyCastleProvider());
		
		//DeBaseUrl64 urlSig to json
		Base64 decoder = new Base64();

		byte [] compressBytes = Base64Url.base64DecodeUrl(sig.getBytes(Charset.forName("UTF-8")));
		
		//Decompression
		Inflater decompression =  new Inflater();
		decompression.setInput(compressBytes, 0, compressBytes.length);
		byte [] decompressBytes = new byte [1024];
		int decompressLength = decompression.inflate(decompressBytes);
		decompression.end();
		
		String jsonString = new String(Arrays.copyOfRange(decompressBytes, 0, decompressLength));
		
		//Get TLS.Sig from json
		JSONObject jsonObject= JSON.parseObject(jsonString);
		String sigTLS = jsonObject.getString("TLS.sig");
		
		//debase64 TLS.Sig to get serailString
		byte[] signatureBytes = decoder.decode(sigTLS.getBytes(Charset.forName("UTF-8")));
		
		String strSdkAppid = jsonObject.getString("TLS.sdk_appid");
		String sigTime = jsonObject.getString("TLS.time");
		String sigExpire = jsonObject.getString("TLS.expire_after");
		
		if (!imConfig.getSdkAppId().equals(strSdkAppid))
		{
			return false;
		}

		if ( System.currentTimeMillis()/1000 - Long.parseLong(sigTime) > Long.parseLong(sigExpire)) {
			return false;
		}
		
		//Get Serial String from json
		String SerialString = 
			"TLS.appid_at_3rd:" + 0 + "\n" +
			"TLS.account_type:" + 0 + "\n" +
			"TLS.identifier:" + identifier + "\n" + 
			"TLS.sdk_appid:" + imConfig.getSdkAppId() + "\n" + 
			"TLS.time:" + sigTime + "\n" + 
			"TLS.expire_after:" + sigExpire + "\n";
	
        Reader reader = new CharArrayReader(imConfig.getPublicKey().toCharArray());
        PEMParser  parser = new PEMParser(reader);
        JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
        Object obj = parser.readObject();
        parser.close();
        PublicKey pubKeyStruct  = converter.getPublicKey((SubjectPublicKeyInfo) obj);

		Signature signature = Signature.getInstance("SHA256withECDSA","BC");
		signature.initVerify(pubKeyStruct);
		signature.update(SerialString.getBytes(Charset.forName("UTF-8")));
		return signature.verify(signatureBytes);
	}catch (Exception e) {
		throw new QCloudException(e);
	}
}
 
開發者ID:51wakeup,項目名稱:wakeup-qcloud-sdk,代碼行數:64,代碼來源:DefaultQCloudClient.java

示例3: decodeWritable

import org.apache.commons.codec.binary.Base64; //導入方法依賴的package包/類
/**
 * Modify the writable to the value from the newValue
 * @param obj the object to read into
 * @param newValue the string with the url-safe base64 encoded bytes
 * @throws IOException
 */
private static void decodeWritable(Writable obj, 
                                   String newValue) throws IOException {
  Base64 decoder = new Base64(0, null, true);
  DataInputBuffer buf = new DataInputBuffer();
  byte[] decoded = decoder.decode(newValue);
  buf.reset(decoded, decoded.length);
  obj.readFields(buf);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:15,代碼來源:Token.java

示例4: decode

import org.apache.commons.codec.binary.Base64; //導入方法依賴的package包/類
/**
 * 使用Base64對已加密數據進行解密
 * 
 * @param encodedText
 * @return
 */
public static String decode(byte[] bytes) {
	Base64 base64 = new Base64();
	bytes = base64.decode(bytes);
	String s = new String(bytes);
	return s;
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:13,代碼來源:Base64Utils.java

示例5: decode64AsString

import org.apache.commons.codec.binary.Base64; //導入方法依賴的package包/類
public static String decode64AsString(String cs)
{
	Base64 base64 = new Base64();
	byte[] arrBytes = cs.getBytes();
	byte[] tOut = base64.decode(arrBytes);
	String csOut = new String(tOut);
	return csOut;
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:9,代碼來源:XMLUtil.java

示例6: decodeBase64

import org.apache.commons.codec.binary.Base64; //導入方法依賴的package包/類
private static String decodeBase64(String base64String) {
  Base64 decoder = new Base64(0, null, true);
  byte[] data = decoder.decode(base64String);
  return new String(data);
}
 
開發者ID:Intel-bigdata,項目名稱:TensorFlowOnYARN,代碼行數:6,代碼來源:ClusterSpec.java

示例7: decode64

import org.apache.commons.codec.binary.Base64; //導入方法依賴的package包/類
public static byte[] decode64(byte[] arrBytes)
{
	Base64 base64 = new Base64();
	return base64.decode(arrBytes);
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:6,代碼來源:XMLUtil.java

示例8: toByte

import org.apache.commons.codec.binary.Base64; //導入方法依賴的package包/類
public static byte[] toByte(String base64Str) throws IOException{ 
       Base64 base64=new Base64();  
       return base64.decode(base64Str);  
}
 
開發者ID:fier-liu,項目名稱:FCat,代碼行數:5,代碼來源:BASE64ConvertUtil.java

示例9: decode

import org.apache.commons.codec.binary.Base64; //導入方法依賴的package包/類
/**
 * 解碼
 * @param content
 * @param encoding
 * @return
 * @throws UnsupportedEncodingException
 */
public static String decode(String content,String encoding) throws UnsupportedEncodingException{
    byte[] b3 = content.getBytes("UTF-8");
    Base64 base64 = new Base64();
    byte[] b4 = base64.decode(b3);
    return new String(b4,encoding);
}
 
開發者ID:kevin-xu-158,項目名稱:JavaNRPC,代碼行數:14,代碼來源:Base64Helper.java


注:本文中的org.apache.commons.codec.binary.Base64.decode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。