Basically I need to have a base64 encoded signature that has to be 96 characters long. However, I do not know what length I need to have the signature at so when I encode it, it can be that exact size. Does anyone know how to convert it? Also, does anyone know how to convert it in base64 encoding or any byte size encoding?
2 Answers
However, I do not know what length I need to have the signature at so when I encode it, it can be that exact size.
Well, base64 uses 4 characters (from an alphabet of size 64) to encode 3 bytes (3 bits contain 24 bits; 24/4 = 6 bits per base64 character).
Hence, if the signature was 72 bytes long, that would translate to 72/3*4 = 96 characters you require.
Now, base64 typically has a === trailer to signify the end of the encoding; are you counting that?
-
$\begingroup$ Okay, thanks a lot for clearing it up poncho. $\endgroup$ Sep 14, 2020 at 22:35
-
2$\begingroup$ Some base64 (mostly PEM and MIME and derivatives thereof) has padding which can be 1 or 2 equalsign but never 3, and is not present if the input is an exact multiple of 3. PGP 'armor' does have a trailer with 1 equalsign followed by 4 base64 chars (exactly) encoding CRC24. $\endgroup$ Sep 15, 2020 at 2:44
-
$\begingroup$ Per Base64, $b>0$ byte(s) encode to $c=4\,\left\lceil b/3\right\rceil$ characters ending in $n=2-(b+2\bmod 3)=(-b)\bmod3$ time(s) the character
=
. And for decoding, $c$ characters with $c$ multiple of $4$, ending in $n$ times the character=
with $0\le n<3$, decode to $b=3\,c/4-n$ byte(s). $\endgroup$– fgrieu ♦Sep 15, 2020 at 5:18 -
$\begingroup$ Can Base64 encoded string end with 3 equal signs?. No! $\endgroup$– kelalakaSep 15, 2020 at 7:46