如何解码以”type*:”前缀存储的base64数据?

huangapple go评论55阅读模式
英文:

How to decode data stored in base64 with "type*:" prefix?

问题

如何解码以下示例的Base64编码字符串?(它存储在MySQL数据库中)

base64:type251:WXlnY2p0bFl5Z2NqdGxZeWdjanRsWXlnY2

我已经尝试使用普通的Base64解码它,但没有成功。前缀中的 "type251" 应该有特殊含义,但我在文档或搜索中没有找到任何信息。

是否有在线工具可用于解码它?

英文:

How do i decode the following example of base64 encoded string? (it is stored on MySQL DB)

base64:type251:WXlnY2p0bFl5Z2NqdGxZeWdjanRsWXlnY2

I have already tried to decode it using normal base64 to no avail. The "type251" prefix should mean something but I haven't found anyting on documentation/googling.

Is there any online tools available to decode it?

答案1

得分: 1

base64:type251:前缀除了对你的应用程序而言没有任何意义。我假设它是一些额外的注释,用于告诉客户端在解码结果后该如何处理。

你展示的字符串'WXlnY2p0bFl5Z2NqdGxZeWdjanRsWXlnY2'不是有效的 base64 字符串,因为它没有填充到八位组的倍数,使其成为24位的倍数。可以阅读维基百科关于 base64 填充的文章:https://en.wikipedia.org/wiki/Base64#Output_padding

尝试解码它将失败并且只会返回 NULL:

mysql> select from_base64('WXlnY2p0bFl5Z2NqdGxZeWdjanRsWXlnY2') as result;
+----------------+
| result         |
+----------------+
| NULL           |
+----------------+

如果添加了一对=填充字符,MySQL 的内置函数可以解码 base64 字符串,但需先去除前缀。

mysql> select from_base64('WXlnY2p0bFl5Z2NqdGxZeWdjanRsWXlnY2==') as result;
+------------------------------------------------------+
| result                                               |
+------------------------------------------------------+
| 0x597967636A746C597967636A746C597967636A746C59796763 |
+------------------------------------------------------+

这是一串二进制字节的字符串,以十六进制数字表示,以便以人类可读的形式显示。

这意味着什么?我不知道。我猜想它是一个 "type251" 的序列化对象实例,这是保存数据的应用程序特有的内容。你并没有描述你的应用程序或者它使用的编程语言。

英文:

The prefix base64:type251: means nothing except to your application. I assume it is some extra annotation to tell the client what to do with the result once it is decoded.

The string you show, 'WXlnY2p0bFl5Z2NqdGxZeWdjanRsWXlnY2' is not a valid base64 string, because it's not padded to sets of octets to make an even multiple of 24 bits. Read the wikipedia article on base64 padding: https://en.wikipedia.org/wiki/Base64#Output_padding

Trying to decode it fails and only returns NULL:

mysql> select from_base64('WXlnY2p0bFl5Z2NqdGxZeWdjanRsWXlnY2') as result;
+----------------+
| result         |
+----------------+
| NULL           |
+----------------+

If a couple of = padding characters are added, MySQL's builtin function can decode the base64 string, after stripping the prefix.

mysql> select from_base64('WXlnY2p0bFl5Z2NqdGxZeWdjanRsWXlnY2==') as result;
+------------------------------------------------------+
| result                                               |
+------------------------------------------------------+
| 0x597967636A746C597967636A746C597967636A746C59796763 |
+------------------------------------------------------+

That's a string of binary bytes, rendered as hex digits so it can be displayed in human-readable form.

What does it mean? I have no idea. I can guess that it's a serialized object instance of "type251" which is something specific to the application that saved that data. You haven't described anything about your application or even what language it's written in.

huangapple
  • 本文由 发表于 2023年2月16日 09:17:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466932.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定