如何将十六进制字符串转换为 base64?我发现这个页面 http://home2.paulschou.net/tools/xlate/ 但我需要一些 java 函数: String base64 = ...decoder(String hex);
我在互联网上找到了一些东西,但它们很难使用字节数组。我正在寻找更简单的东西,非常感谢
原文由 hudi 发布,翻译遵循 CC BY-SA 4.0 许可协议
如何将十六进制字符串转换为 base64?我发现这个页面 http://home2.paulschou.net/tools/xlate/ 但我需要一些 java 函数: String base64 = ...decoder(String hex);
我在互联网上找到了一些东西,但它们很难使用字节数组。我正在寻找更简单的东西,非常感谢
原文由 hudi 发布,翻译遵循 CC BY-SA 4.0 许可协议
首先你必须导入 Apache Commons Codec 库! https://commons.apache.org/proper/commons-codec/archives/1.9/index.html
这是 1.9 版本的 API http://commons.apache.org/proper/commons-codec/archives/1.9/apidocs/index.html
那么你必须按照这3个步骤
//convert String to char array (1st step)
char[] charArray = myhexString.toCharArray();
// decode the char array to byte[] (2nd step)
byte[] decodedHex = Hex.decodeHex(charArray);
// The String decoded to Base64 (3rd step)
String result= Base64.encodeBase64String(decodedHex);
原文由 gtopal 发布,翻译遵循 CC BY-SA 3.0 许可协议
15 回答8.4k 阅读
8 回答6.2k 阅读
1 回答4k 阅读✓ 已解决
3 回答6k 阅读
3 回答2.2k 阅读✓ 已解决
2 回答3.1k 阅读
2 回答3.8k 阅读
看看 Commons 编解码器: