Which is the best method to detect if a string is Base64Encoded or not (using Delphi)?
相关问题
- Is there a Delphi 5 component that can handle .png
- Is there a way to install Delphi 2010 on Windows 2
- Is TWebBrowser dependant on IE version?
- ruby 1.9 wrong file encoding on windows
- iOS objective-c object: When to use release and wh
相关文章
- iconv() Vs. utf8_encode()
- When sending XML to JMS should I use TextMessage o
- Best way to implement MVVM bindings (View <-> V
- Google app engine datastore string encoding proble
- Windows EventLog: How fast are operations with it?
- How to force Delphi compiler to display all hints
- Coloring cell background on firemonkey stringgrid
- How can i get know that my String contains diacrit
Best you can do is try to decode it. If the decode fails then the input was not base64 encoded. It the string successfully decodes then the input might have been base64 encoded.
You can check if the string only contains Base64 valids chars
The
=
char is used for padding so you can add an aditional valiation to the function for padded base64 strings checking if the length of the string is mod 4In addition to RRUZ answer you can also check the length of the string (is it a multiple of 4).
Please note that this code is Delphi 7 code and not adjusted for Unicode use.
As was already told here, there is no reliable verification if a certain string is Base64 encoded or not, so even when you consider the input as a valid Base64 encoded string, it doesn't mean the string is actually encoded that way. I'm posting here just another version of a validation function, which according to
RFC 4648
verifies:Page 5, Table 1
)