在线编码解码工具
Base64并不是安全领域的加密算法,其实Base64只能算是一个编码算法,对数据内容进行编码来适合传输。标准Base64编码解码无需额外信息即完全可逆.
对于非二进制数据,是先将其转换成二进制形式,然后每连续6比特(2的6次方=64)计算其十进制值,根据该值在A-Z,a-z,0-9,+,/这个64个字符中找到对应的字符,最终得到一个文本字符串。
1、编码方法
public static String encodeToString(byte[] input, int flags)
public static String encodeToString(byte[] input, int offset, int len, int flags)
public static byte[] encode(byte[] input, int flags)
public static byte[] encode(byte[] input, int offset, int len, int flags)
flags的取值
- Base64.DEFAULT 默认
- Base64.NO_PADDING :Encoder flag bit to omit(忽略) the padding ‘=’ characters at the endof the output (if any).
- Base64.NO_WRAP : Encoder flag bit to omit all line terminators(终结者即换行符) (i.e., the output will be on one long line).
- Base64.CRLF : Encoder flag bit to indicate lines should be terminated with a CRLF pair instead of just an LF. Has no effect if {@code NO_WRAP} is specified as well.
- Base64.URL_SAFE :这个参数意思是加密时不使用对URL和文件名有特殊意义的字符来作为加密字符,具体就是以-和_取代+和/
2、解码方法:
public static byte[] decode(String str, int flags)
public static byte[] decode(byte[] input, int flags)
public static byte[] decode(byte[] input, int offset, int len, int flags)