I need your help, because I have tried multiple options and I cannot find the solution: I have this
cadenaEnBase64="ewAiAEQAYQB0AGUAIgA6ACIAMQAxAC8AMAAzAC8AMgAwADIAMQAiACwAIgBJAGQAZQBuAHQAaQB0AHkAIgA6ACIAcwBmAHMAZgBqAGkAZgBuAGQAaQBmAGgAZABmADIANAA2ADQAMQAiACwAIgBEAGEAdABlAEUAcwAiADoAIgAwADEALwAxADIALwAyADAAMgAxACIALAAiAEQAYQB0AGUARQBMACIAOgAiADAAMQAvADEAMgAvADIAMAAyADIAIgAsACIAVABpAHAAbwBzAEwASQBDAEUATgBDAEkAQQAiADoAOQAsACIAQQBjAHQAaQB2AGUAIgA6AHQAcgB1AGUALAAiAEwAaQBjAGUAbgBzAGUAXwBOACIAOgAxADIANQAxAH0A"
I want to decode it to this (this is the result):
{"Date":"11/03/2021","Identity":"sfsfjifndifhdf24641","DateEs":"01/12/2021","DateEL":"01/12/2022","TiposLICENCIA":9,"Active":true,"License_N":1251}
you can test the result at: https://www.base64decode.org/
but with Delphi 10.3 nor 7 I have obtained results, it shows only the first key:
{
That is the only result I get.
Quick (and short) answer
Use this function to decode the string:
For example, like this:
Let's talk Base64
To begin with, always keep in mind that Base64 is essentially an encoding algorithm that allows you to represent anything in your computer's memory using ASCII characters. That is, it can be used to encode/decode any block of information, not just text. This means that when you encode text, you are actually encoding the memory representation of that text.
In fact, Base64 encoding/decoding algorithms often work with streams or arrays of bytes, completely ignoring what is represented by those bytes.
Base64 of text strings
Some people, for convenience, often create routines to encode/decode text strings that make use of these algorithms. In doing so, the most common thing in modern times is to use UTF8 to represent the string before encoding it, so that any Unicode character can be represented while keeping a minimum size in memory. This is more or less a de-facto standard (as far as I know, it's not written in any rules that it has to be done that way, and in fact not everyone respects it).
Taking into account what has been said so far, it falls to its own weight to deduce that the result of the encoding process will not be the same if we apply it to a text string with UTF8 format, than with UTF16, ASCII or ANSI, since the same string can have a different representation in memory between one and the other. In fact, in the Unicode world, it will always have a different representation between UTF8/UTF16, since in one the base character occupies 1 byte of memory and in the other it occupies 2.
And it goes without saying that when it is decoded, since what is obtained is a few bytes in memory, if it is not interpreted under the same encoding, errors will occur and in the end a different string will be obtained from the one that was encoded. This is the situation we see in this case.
Inspecting the result of decoding the string you present, we can see that every second byte is 0. For example, running this code in Delphi:
If we put a breakpoint, execute the line of code and see the local variables window, it shows us something like the following:
This quickly made me think that the original string had characters from the Latin alphabet, represented as UTF 16 (where the second byte is regularly 0).
Therefore, the solution routine directly applies this encoding to re-interpret the bytes as a string, which returns the following text:
My recomendation:
All that said, if you have control over where the original string is base-64 encoded, it's best to encode the UTF8 representation of this string. If this is done with Delphi, as simple as calling:
This, as I said before, is the de facto standard of the network.
Welcome to stackoverflow in Spanish.
As for your question, I think you are having problems with the encoding, since the page you are commenting on is not doing the decoding correctly.
For example, if you try these (although you can find more), with the chain you have placed, you will see that the result in all of them is similar, but it is not what you expected:
The correct result appears in the result, but with incorrect characters inserted. It looks like what you're sending is not in the correct encoding.
If you encode the string with any of those pages, the result is similar on all of them:
String:
String in Base64:
If you encode and decode this same string (the original) with Delphi, you will get the expected result. The code is simple, as Delphi has a base64 encode/decode unit .
With code like this you can encode and decode it:
And this is the result:
So I deduce that you have a problem with the initial string. You would have to know where you got it from or how it was encrypted.