如何识别使用的是哪种编码算法? [英] How to identify which encoding algorithm is used?

查看:42
本文介绍了如何识别使用的是哪种编码算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个纯文本及其编码的字符串,我想知道使用哪种编码器/算法对字符串进行编码.

I have a plain text and its encoded string, I wanted to know which encoder/algorithm is used to encode the string.

纯文本:hello world
编码文本:3MZ7hIAnvqtIqnxZJyEi+dOuJ1/myCfsbYOCsYKkZto=

我知道它与 base64 有关,但我试过它对我不起作用.

I know it has something to do with base64, but I have tried it not working for me.

我有一个像exe这样的记事本,我在里面写了hello world"然后保存了它.当我在普通记事本中打开文本文件时,它会显示3MZ7hIAnvqtIqnxZJyEi+dOuJ1/myCfsbYOCsYKkZto=".当我在 exe(我写的地方)中打开同一个文件时,它显示纯文本hello world".

I have a notepad like exe, in which I wrote "hello world" then saved it. When I open the text file in a normal notepad it shows me "3MZ7hIAnvqtIqnxZJyEi+dOuJ1/myCfsbYOCsYKkZto=". And When I open the same file in the exe (where I wrote), it shows plain text "hello world".

推荐答案

关于 base64 编码字符串有两个常见的误解/误解:

There are two common misunderstandings/misconceptions regarding base64 encoded strings:

  1. 对base64编码字符串解码后获得可读文本的期望,以及编码不同或base64解码器在结果不符合期望时不起作用的假设

    给定的字符串似乎是 base64 编码的,它只包含 base64 字符集中的字符并且它被正确填充,所以它很可能是一个 base64 编码的字符串.Base64 编码用于对所有类型的数据进行编码,但一个非常常见的用例是将二进制数据(不可打印或仅显示为奇怪"符号的字符串)编码为更易于处理的形式.一个典型的用例是对加密或散列的结果进行 base64 编码,这两者都会产生二进制结果.

  1. The expectation to get readable text after decoding a base64 encoded string, along with the assumption that either the encoding is different or the base64 decoder doesn't work when the result doesn't meet the expectation

    The given string seems to be base64 encoded, it only contains characters from the base64 character set and it is correctly padded, so it's very likely a base64 encoded string. Base64 encoding is used to encode all kinds of data, but a very common use case is to encode binary data (that would not be printable or only shown as a string of 'weird`' symbols) into an easier to handle form. One typical use case is to base64 encode the result of encryption or hashing, which both create binary results.

期望base64解码是取回原件的唯一必要步骤(例如纯文本、密码等)

如上所述,base64通常用于对二进制结果进行编码加密或散列.Base64 本身并不是加密,并且(希望)从未用于保护密码或其他机密信息.
《你好世界》在 base64 编码中是aGVsbG8gd29ybGQ=",每个人都可以使用任何base64 解码器对其进行解码.
密码的过程通常是先对密码进行散列,然后对二进制散列值进行base64 编码.对于其他机密信息,它会先加密,然后再进行 base64 编码.

The expectation that base64 decoding is the only step necessary to get back the original (e.g. plain text, password, etc.)

As mentioned above, base64 is often used to encode the binary result of encryption or hashing. Base64 alone is not encryption and (hopefully) never used to secure passwords or other confidential information.
"hello world" in base64 encoding is "aGVsbG8gd29ybGQ=", and everyone can decode it with any base64 decoder.
The process for passwords is usually to first hash the password and then base64 encode the binary hash value. For other confidential information it's encrypting and then base64 encoding.

话虽如此,结论是给定的字符串可能是 base64 编码的哈希或加密文本.

Having said this, the conclusion is that the given string is likely a base64 encoded hash or encrypted text.

典型的后续问题是:
如果我从解码中得到的这个二进制乱码是加密或散列的结果,我如何获得纯文本?

The typical follow up question is:
If this binary gibberish that I get from decoding is the result of encryption or hashing, how do I get the plain text?

对此的答案是:可能根本不是,至少不是基于给定的信息.

The answer for this is: probably not at all, at least not based on the given information.

如果是散列,则无需解密,因为散列是单向过程.如果它是加密的,则没有信息如何解密.对于解密,您需要知道加密算法和密钥.

在散列或加密的情况下,二进制信息通常不包含任何标记,将数据标记为任何特定散列或加密算法的结果.
我可以从 base64 编码字符串(除了二进制结果)获得的唯一信息是长度.给定的字符串长度为 44 个字符,包括一个填充字符,即 43 * 6(每个 base64 字符编码 6 位)= 258 位,因此可能是 256 位.例如,这可能是 sha-256 哈希,但实际上只是一种可能性.

If it's a hash, there is nothing to decrypt as hashing is a one-way process. If it's encrypted, there is no information how to decrypt this. For decryption you would need to know the encryption algorithm and the key.

And in case of hashing or encryption, the binary information usually doesn't contain any marker that marks the data as being the result of any certain hashing or encryption algorithm.
The only information I can get from the base64 encoded string (aside from the binary result) is the length. The given string is 44 characters long including one padding character, that's 43 * 6 (every base64 character encodes 6 bits) = 258 bits, so probably 256 bits. That could be, for example, a sha-256 hash, but really just a possibility.

后面关于程序存储base64字符串并读取原始数据的问题中增加了一段使 base64 字符串可能包含加密信息,但这就是我能从中获得的全部信息.

The later added paragraph in the question about the program that stores the base64 string and retrieves the original data after reading it makes it likely that the base64 string contains encrypted information, but that's all I can get from it.

这篇关于如何识别使用的是哪种编码算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆