简体   繁体   English

如何检查字节数组是Base64编码的?

[英]How to check that byte array is Base64 encoded?

How to check that byte array is Base64 encoded? 如何检查字节数组是Base64编码的?

I have an array of bytes, which I need to test if it is base64 encoded. 我有一个字节数组,需要测试它是否是base64编码的。

You can use apache's Base64.isBase64(byte[]) method: 您可以使用apache的Base64.isBase64(byte [])方法:

import org.apache.commons.codec.binary.Base64;

...

boolean isBase64 = Base64.isBase64(bytes);

Base64-encoded strings have length divisible by 4, and consist of characters A - Z , a - z , 0 - 9 , + , and / . Base64编码串具有长度被4整除,和由字符A - Za - z0 - 9+ ,和/ If your array of bytes has length that is not divisible by 4, or contains bytes that map to characters outside these ranges, then it does not represent a Base64-encoded string; 如果您的字节数组的长度不能被4整除,或者包含映射到这些范围之外的字符的字节,则它不表示Base64编码的字符串; otherwise, your array of bytes represents a valid Base-64 encoded string. 否则,您的字节数组代表有效的Base-64编码字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将字节数组读入base64编码的图像 - Read byte array into base64 encoded image 如何检查“byte [] b”(保存文件内容)是否在base64中编码..? 在java中 - How to check a “byte[] b” (holding a file content) is encoded in base64 or not..? in java 如何将图像的字节数组转换为表示jpg的base64编码字符串 - How to convert byte array of an image to a base64 encoded string representing a jpg Android:如何检查字符串是否为 Base64 编码? - Android: How to check if string is Base64 encoded? 如何检查 InputStream Base64 是否编码? (不转换为字节) - How to check is InputStream Base64 encoded? (without converting to bytes) 如何检查txt文件是否为base64编码 - how to check whether a txt file is base64 encoded or not 如何检查字符串是否为base64编码? - How to check whether a string is base64 encoded or not? Java Base64编码的字节数组到javax.activation.DataHandler - Java Base64 encoded byte array to javax.activation.DataHandler 解码(通过python类型转换将类型转换为字符串的Base64编码数据)转换为JAVA中的字节数组 - Decoding (Base64 encoded data with type conversion to string by python type casting) to byte array in JAVA 在Android中将字节数组转换为base64字符串时获取损坏的编码数据 - Get corrupted encoded data while converting byte array to base64 string in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM