本文整理匯總了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) );
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例7: decode64
import org.apache.commons.codec.binary.Base64; //導入方法依賴的package包/類
public static byte[] decode64(byte[] arrBytes)
{
Base64 base64 = new Base64();
return base64.decode(arrBytes);
}
示例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);
}
示例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);
}