简体   繁体   English

"如何将“二进制字符串”转换为 base64?"

[英]How to convert a "binary string" to base64?

I've followed this: https:\/\/dev.twitter.com\/docs\/auth\/creating-signature<\/a>我遵循了这个: https<\/a> :\/\/dev.twitter.com\/docs\/auth\/creating-signature

to the end but I can't find how to encode a "binary string" to base64(at the end).到最后,但我找不到如何将“二进制字符串”编码为 base64(最后)。 I wanted to try online converters first but they don't give the string the show "tnnArxj06cWHq44gCs1OSKk\/jLY="我想先尝试在线转换器,但他们没有给字符串显示“tnnArxj06cWHq44gCs1OSKk\/jLY=”

Tried this: http:\/\/www.motobit.com\/util\/base64-decoder-encoder.asp<\/a>试过这个: http<\/a> :\/\/www.motobit.com\/util\/base64-decoder-encoder.asp

and

http:\/\/www.hash-cracker.com\/base64.php#anchor<\/a> http:\/\/www.hash-cracker.com\/base64.php#anchor<\/a>

and

http:\/\/www.opinionatedgeek.com\/dotnet\/tools\/Base64Encode\/<\/a> http:\/\/www.opinionatedgeek.com\/dotnet\/tools\/Base64Encode\/<\/a>

and none give that string.没有人给出那个字符串。

I'm going to be using java.我将使用java。 But I think all those java tools I search for will give the same result as the online converters.但我认为我搜索的所有这些 java 工具都会给出与在线转换器相同的结果。 What has to be done to encode a "binary string" to base64?将“二进​​制字符串”编码为 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. 使用这些在线工具的问题不会在base64转换中 - 它将把十六进制字符串解析为字节数组开始。 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 : 为了证明这一点,这里有一些示例Java代码,使用公共域base64编码器

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= 输出:tnnArxj06cWHq44gCs1OSKk / jLY =

您可以使用此链接将二进制字符串转换为 Base64 https://cryptii.com/pipes/binary-to-text

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM