Decoding a Base64 string in Java

前端 未结 4 1702
心在旅途
心在旅途 2020-12-05 09:15

I\'m trying to decode a simple Base64 string, but am unable to do so. I\'m currently using the org.apache.commons.codec.binary.Base64 package.

The test

4条回答
  •  一生所求
    2020-12-05 09:56

    The following should work with the latest version of Apache common codec

    byte[] decodedBytes = Base64.getDecoder().decode("YWJjZGVmZw==");
    System.out.println(new String(decodedBytes));
    

    and for encoding

    byte[] encodedBytes = Base64.getEncoder().encode(decodedBytes);
    System.out.println(new String(encodedBytes));
    

提交回复
热议问题