java二进制细节转base64,如何转换“二进制字符串”?到base64?

to the end but I can't find how to encode a "binary string" to base64(at the end). I wanted to try online converters first but they don't give the string the show

"tnnArxj06cWHq44gCs1OSKk/jLY="

and

and

and none give that string.

I'm going to be using java. But I think all those java tools I search for will give the same result as the online converters. What has to be done to encode a "binary string" to base64?

解决方案

The problem of using those online tools isn't going to be in the base64 conversion - it's going to be parsing the hex string into a byte array to start with. In your real code that won't be a problem, as it'll be the output of another stage. Just to prove that, here's some sample Java code, using a public domain base64 encoder:

public class Test {

public static void main(String[] args) throws Exception {

byte[] data = { (byte) 0xB6, (byte) 0x79, (byte) 0xC0, (byte) 0xAF,

(byte) 0x18, (byte) 0xF4, (byte) 0xE9, (byte) 0xC5,

(byte) 0x87, (byte) 0xAB, (byte) 0x8E, (byte) 0x20,

(byte) 0x0A, (byte) 0xCD, (byte) 0x4E, (byte) 0x48,

(byte) 0xA9, (byte) 0x3F, (byte) 0x8C, (byte) 0xB6 };

String text = Base64.encodeBytes(data);

System.out.println(text);

}

}

Output: tnnArxj06cWHq44gCs1OSKk/jLY=

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值