Java.util.Base64 decodes and then encodes, gives another line

Problem: decoding Fz + =, and then encoding it returns Fz8 =

The following code:

new String(Base64.getEncoder().encode(Base64.getDecoder().decode("Fz+=".getBytes("UTF-8"))))

Gives the following line:    FZ8 =

How did + become 8?

Something is missing for me.

Fz + = in the bit scheme: 000101 110011 111110 000 000

regrouped into 8-bit groups: 00010111 00111111 10000000

Decimal: 23 63 128

which will require 3 bytes to represent it.

However, when I try only this code:

Base64.getDecoder().decode("Fz+=".getBytes("UTF-8"))

I get the following array in decimal form:

 [23, 63]

Where did the last byte (1000 0000) go? This is the reason the + symbol turned into 8 when we encoded it.

+4
source share
1 answer

Fz+= Base64.

, , , , . 0x00, 3- , 4 Base64.

, Fz+=, 2- 0x80. , 0x80 0x00, 7- ASCII.

, Fz+= , .

00010111 00111111 10000000, Fz+A A , 000000. , , , ​​, .

+4

Source: https://habr.com/ru/post/1691639/


All Articles