当前位置: 首页>>代码示例>>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;未经允许,请勿转载。