如何解码base64编码的字体信息?
我遇到一个使用编码字体信息的网站。 我尝试通过 Base64 Endoder/Decoder Web 服务将此编码字体转换为二进制文件,但我无法找出生成的文件的格式是什么。
这里是编码的CSS内容(内容太大,无法在此处复制/粘贴)。
谢谢!
[编辑]
请不要猜测我想做什么。
我正在询问有关如何伪造 Base64 代码以及我缺少什么才能逆转该过程的问题,这意味着我不明白其中的一切。这些技术通常用在带有自定义字体的网页中,并且与 CSS 文件中直接给出引用的原始字体文件相比似乎有一些改进。我完全清楚涉案字体属于商业字体,不能随意使用。
这场辩论偏离了主题,停止恶搞。
I encountered a website which used encoded font information.
I tried to convert this encoded font to a binary file through the Base64 Endoder/Decoder Web service, but I couldn't find out what is the format of the resulting file.
Here is the encoded CSS content (the content is too big to be copied/paste here).
Thanks!
[EDIT]
Please don't speculate on what I want to do.
I am asking questions about how the base64 code has been forged and what I am missing to be able to reverse the process, which means I do not understand everything in it. These technique is often used in webpages with custom fonts, and seems to have some improvements compared to the raw font file directly given reference in the CSS file. I am fully aware that the involved fonts are commercial ones and can't be used freely.
That debate is off-topic, stop trolling.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
1) 找到完整的字体声明,例如
data:font/opentype;base64,AaBbCcDdEeFf0123456789==
2) 复制编码数据部分;排除前导类型声明和逗号。
删除这个
data:font/opentype;base64,
你想要这个:
AaBbCcDdEeFf0123456789==
3) 解码数据并保存为二进制编码文件。 请勿解码数据并将结果手动粘贴到文本编辑器中。使用 http://www.motobit.com/util/base64-decoder-encoder。 asp 选择“从 Base64 字符串解码数据”和“导出到二进制文件”选项。
4) 使用纯文本编辑器查看文件。文件的前 3 或 4 个字母可能是“woff”、“otf”或“ttf”。这是您的实际文件类型。
1) locate the complete font declaration, for example,
data:font/opentype;base64,AaBbCcDdEeFf0123456789==
2) copy the encoded data portion; exclude the leading type declaration and comma.
Drop this
data:font/opentype;base64,
You want this:
AaBbCcDdEeFf0123456789==
3) decode the data and save as a binary encoded file. Do not decode the data and manually paste the result into a text editor. Use http://www.motobit.com/util/base64-decoder-encoder.asp Select the "decode the data from a Base64 string" and "export to a binary file" options.
4) View the file using a plain text editor. The first 3 or 4 letters of the file are probably "woff", "otf", or "ttf". This is your actual file type.
将
data:application/font-woff;base64,d09GRgABAA.....
粘贴到浏览器(最好是 Chrome)地址栏中。它将下载文件,使用正确的文件扩展名重命名该文件(例如data:application/font-woff
是.woff
,data:application/font- woff2
是.woff2
等...)。这适用于任何字体文件。Paste
data:application/font-woff;base64,d09GRgABAA.....
in the browser (ideally Chrome) address bar. It will download the file, rename the file with proper file extension (e.g.data:application/font-woff
is a.woff
,data:application/font-woff2
is a.woff2
, etc...). This will work with any font file.这是一个有趣的问题,尽管它对海盗猎人来说很有吸引力。我将重点关注技术问题并尝试提供一些见解。
查看OP的文件,里面有六种字体。每一条基本上都是 CSS 规则;这是示例文件中的第一个:
这告诉您识别字体所需了解的所有信息。您可以看到其名称 (p22-underground-1)、样式 (normal)、重量 (400) 和类型 (opentype )。
至于将字体从base64解码为二进制文件,您需要采用base64位(如上所示
d09GRk9...yn4b8C3JEZAA==
,注意中心的大部分已被删除以节省空间此处)并使用 Base64 解码器对其进行解码,例如 Motobit 或通过编写程序。如果您使用的是 Linux,则可以使用
base64 -d
来实现相同的效果。如果解码失败,base64 字符串也可能是百分比转义。 OP的例子并非如此,但我知道至少有一个网站是这种情况。
您可以通过在 Base64 字符串中查找百分比
%
符号来检查这一点。如果百分比字符是唯一的非有效 base64 字符,那么您可以尝试对字符串进行转义在解码之前。有一个网站,您可以在其中执行此操作,或者,对于 Linux 上的用户,可以使用命令行方法如下所示(有很多方法可以做到这一点;这个使用 Perl):
我用 Ruby 编写了一个小工具,它接受一个 url 并使用上述技术将任何嵌入的字体转储到文件中,所以我可以说它们确实有效。
This is an interesting question, despite being a magnet for pirate hunters. I will focus on the technical question and try to give some insight.
Looking at the OP's file, there are six fonts in it. Each one is basically a CSS rule; here's the first one in the example file:
This tells you everything that you need to know to identify the font. You can see its name (p22-underground-1) its style (normal), weight (400) and type (opentype).
As for decoding the font from base64 into a binary file, you need to take the base64 bit (shown above as
d09GRk9...yn4b8C3JEZAA==
, note the bulk in the cenre has been removed to save space here) and decode it with a base64 decoder such as Motobit or by writing a program.If you're on Linux, you can use
base64 -d <file>
to achieve the same thing.If the decoding fails, the base64 string may be also be percent-escaped. This isn't the case with the OP's example but I know of at least one site where this is the case.
You can check for this by looking for percent
%
symbols in the base64 string. If percent characters are the only non-valid base64 characters then you can try to unescape the string prior to decoding.There is a web site where you can do this or, again, for those on Linux, a command-line method is shown below (there are many ways to do this; this one uses Perl):
I wrote a small tool in Ruby that takes a url and dumps any embedded fonts into files using the above techniques so I can say that they do work.
CSS 明确规定 mimetype 为
font/opentype
... 字体采用 OpenType (.otf
) 格式。但是,即使您确实解码了字体,也请检查许可证。您可能不被允许在自己的项目中使用该字体。
CSS 文件中引用的字体 (Proxma Nova [Mark Simonson Studios] 和 < a href="http://www.p22.com/products/london.html" rel="nofollow">P22 Underground [P22 Type Foundry]) 不是免费。您需要购买许可证才能合法使用它们。
The CSS clearly states the mimetype to be
font/opentype
... The font is in OpenType (.otf
) format.However, even if you do decode the font, please check the license. You might not be allowed to use that font in your own projects.
The fonts referenced in the CSS files (Proxma Nova [Mark Simonson Studios] and P22 Underground [P22 Type Foundry]) are not free. You need to purchase a license to use them legally.