混淆 Base 64 字符串的好方法是什么?
Base64 编码通常用于混淆明文,我想知道是否有任何快速/简单的方法来混淆 Base 64 字符串,以便它不容易被识别。为此,该方法应该混淆填充字符(=),使它们成为其他符号并且更加分散。
有谁知道一种简单(且易于逆转)的方法来做到这一点?
您可以使用移位密码,但我正在寻找更全面的东西,例如,如果我的移位密码映射到 a,有人可能会注意到一个经常以 a 结尾的字符串。
目的不是为了增加安全性,实际上只是让base64无法被识别为base 64。它也不需要通过安全专业人员,只需要一个知道base64是什么以及它是什么样子的人即可。 Ex(= 在末尾等)
我描述的方法可能会添加非基数 64 字符,例如 ^%$#@!,以帮助混淆读者。
大多数回复似乎都是关于为什么我想这样做的主题,基本答案是该操作将完成多次(所以我想要一些便宜的东西),并且以一种不存在的方式完成密码可以被记住(为什么我不进行异或)。此外,这些数据并不高度敏感,只是用作针对普通用户的一种方法,他们可能知道什么是 64 进制字符串。
Base64 encoding is often used to obfuscate plaintext, I am wondering if there are any quick/easy ways of obfuscating a base 64 string, so that it is not easily recognizeable as such. To do so the method should obfuscate the padding characters (='s) such that they become some other symbol and are more dispersed.
Does anyone know of an easy (and easily reversible) way to do this?
You could use a shift cipher, but I am looking for something that's a little more comprehensive, for example if my shift cipher mapped = to a, someone might notice a string that frequently ends in a's.
The purpose is not to add security, it is actually simply to make base64 unrecognizeable as base 64. It also does not need to pass a security proffesional, just an individual that knows what base64 is and what it looks like. Ex (='s at the end etc.)
The method I describe would probably add non base 64 characters, like ^%$#@!, to help obfuscate the reader.
Most of the replies seem to be on the topic of WHY I would want to do this, and the basic answer is that the operation would be completed numerous times (So I want something inexpensive), and done in a way where no password can be remembered (Why I don't XOR). Also the data isn't highly sensitive, and is just to be used as a method against the casual user, who might have knowledge of what a base 64 string is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
一些建议:
xor
每个字符及其位置,模 256。这将消除任何简单的统计分析,因为每个字符的映射取决于字符串中的位置。A couple of suggestions:
xor
each character with it's position, modulo 256. This will eliminate any simple statistical analysis since the mapping of each character depends on the position in the string.与 Anders Abel 的最佳答案中的要点之一相反,base64 字符串中的 = 符号似乎很重要:
In contrast to one of the points in Anders Abel's best answer, the = signs in the base64 strings seem to matter:
您所要求的称为“默默无闻的安全性”,通常是一个坏主意。
Base64 编码从来没有被设计或意图用于混淆文本或数据。它用于对需要通过某些仅允许 ASCII 字符(例如电子邮件消息)或 XML 的一部分等的通信通道传输的二进制数据进行编码。
如果您想隐藏数据,最好使用真正的加密。无论如何,即使在加密数据之后,您也需要将其作为 XML 等传递,您最终可能会再次将其编码为 Base64 以用于传输目的。
What you are asking for is called "security by obscurity" and generally is a bad idea.
Base64 encoding was never designed or intended to be used to obfuscate text or data. Its used to encode binary data which needs to travel trough some communication channel which allows only ASCII characters - like email messages, or be part of XML, etc.
Better use real encryption if you want to hide the data. In any case, even after encrypting the data, you need to pass it as XML, etc., you may end up again encode it in Base64 for transport purposes.
我想您可以生成少量随机数据,然后使用它来编码 Base64 字符。将随机数据添加到重新编码的 Base64 数据之前。
一个非常简单的示例:给定输入字符串“Hello”,生成 1-9 范围内的随机数,并将其用作应用于每个输入字符的偏移量。假设您生成“5”,那么重新编码的字符串将为“5Mjqqt”。或者将偏移量编码为字母而不是数字(a=1,b=2,...),然后“=”填充每次都会被转换为不同的字符。
或者你可以直接去掉填充物;根据维基百科文章,这并不是真正必要的。
(但是首先要考虑一下这是否真的是必要且充分的事情。从您的问题中并不清楚为什么要混淆 64 进制数据。)
I suppose you could generate a small amount of random data, and then use that to encode the Base64 characters. Prepend the random data to the re-encoded Base64 data.
A very simple example: given an input string "Hello", generate a random number in the range 1-9 and use that as the offset to apply to each input character. Suppose you generate "5", then the re-encoded string would be "5Mjqqt". Or encode the offset as a letter rather than as a number (a=1, b=2, ...) Then the "=" padding will be translated to a different character each time.
Or you could just drop the padding; according to the Wikipedia article, it's not really necessary.
(But consider whether this is really a necessary and sufficient thing to be doing in the first place. It's not clear from your question why you want to obfuscate base 64 data.)
如果您的要求实际上是阻止决心解码数据的人逆转该过程,则同意建议使用加密的答复。
否则,答案在某种程度上取决于系统的其他约束,但我想到了一些想法。如果您只关心分隔符,并且您可以控制生成 Base64 的过程,您可以选择某种在转换之前填充数据的方法,从而消除 ' =' 输出中的字符。
沿着同样的思路,您可以使用“base64url”编码等变体之一(请参阅 http://en. wikipedia.org/wiki/Base64 了解有关不使用 pad 字符的变体的大量有用信息。
通过其中一种方法消除“=”后,您也许可以对生成的 Base64 进行某种字符交换,只需交换所有其他字符,仅保留任何最终字符。您也许还可以将大写或小写字母替换为其他一些字符,使其乍一看不像 Base64。
然而,无论您选择什么想法,只要记住,如果您需要真正保护该数据,它就不能替代真正的加密方案。
agreed with the responses suggesting use of encryption if your requirements are to actually keep someone who is determined to decode the data from reversing the process.
otherwise, the answer somewhat depends on other constraints of your system, but a few ideas came to mind. if you're just concerned about the delimiter characters, and you have control over the process that generates the Base64 to begin with, you could choose some method of padding the data prior to conversion, thus eliminating the '=' characters from the output.
along this same vein, you could use one of the variants like 'base64url' encoding (see http://en.wikipedia.org/wiki/Base64 for lots of good info on the variants) that does not use the pad character.
after eliminating the '=' by one of these methods, you could perhaps do some sort of char-swapping on the generated Base64, just swapping every other character, just leaving any final character in place. you could also perhaps do some sort of substitution of the upper- or lowercase letters into some other characters to make it look less like Base64 to a quick glance.
however, whatever idea you choose, just remember that it will not be a substitute for a real encryption scheme if you require real protection of that data.
当您希望数据通过某个可能会扭曲非字母数字符号的通道(例如在 XML 中)时,通常会使用 Base64。如果这也是您的任务 - 无论您如何尝试,您的代码都将类似于 Base64 :)
如果您的通道可以很好地处理二进制数据 - 那么只需获取源文本(解码回 Base64),获取它的二进制表示形式并使用某种异或。例如,对源字节中的每个字节进行
xor 37
。相同的操作将恢复您的文本。但任何具有密码分析基础知识的人仍然可以轻松识别它。如果有问题 - 使用真正的加密。
Base64 usually used when you want your data goes through some channel that can distort non-alpha-numeric symbols - for example in XML. If it is your task too - your code will be similar to Base64 no matter how you try :)
If your channel handles binary data well - then just get source text (decode Base64 back), get binary representation for it and use some sort of
xor
. For example makexor 37
with every byte in source bytes. The same operation will restore your text back.But it still easily recognizable by anyone who has basic knowledge of cryptanalysis. If it is a problem - use real encryption.