简体   繁体   English

如何在java中将base16转换为base 64,反之亦然?

[英]How to Convert base16 to base 64 in java and vice versa?

How to convert base16 to base64 nad vice versa in java?can anyone help me by providing the code.如何在java中将base16转换为base64,反之亦然?任何人都可以通过提供代码来帮助我。

the value in base16 is : 567a3b23b683d8488d5d40d2a56e31d2 base16值为: 567a3b23b683d8488d5d40d2a56e31d2
the value in base64 is : Vno7I7aD2EiNXUDSpW4x0g== base64值为: Vno7I7aD2EiNXUDSpW4x0g==

i'm expecting to get the 2nd value if i provided 1st one as input and convert base16 to base64 .如果我提供第一个值作为输入并将base16转换为base64我希望得到第二个值。

i'm getting the result on this website if i provide these values.如果我提供这些值,我就会在这个网站上得到结果。

the value in base16 is : 567a3b23b683d8488d5d40d2a56e31d2 . base16值为: 567a3b23b683d8488d5d40d2a56e31d2
the value in base64 is : Vno7I7aD2EiNXUDSpW4x0g== base64值为: Vno7I7aD2EiNXUDSpW4x0g==

If you can use external libraries, the easiest thing would be to let something like Apache Commons Codec do the heavy lifting - decode the input using Hex and then encode it using Base64 :如果您可以使用外部库,最简单的方法就是让 Apache Commons Codec 之类的东西完成繁重的工作 - 使用Hex解码输入,然后使用Base64对其进行编码:

String base16input = "567a3b23b683d8488d5d40d2a56e31d2";
byte[] decoded = new Hex().decodeHex(base16input);
String base64output = new String(new Base64().encode(decoded));

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

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