简体   繁体   English

如何解码base64编码的字体信息?

[英]How to decode base64-encoded font information?

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.我试图通过Base64 Endoder/Decoder Web 服务将此编码字体转换为二进制文件,但我无法找出生成的文件的格式。

Here is the encoded CSS content (the content is too big to be copied/paste here).是编码的 CSS 内容(内容太大,无法在此处复制/粘贴)。

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.我问的问题是关于 base64 代码是如何伪造的,以及我缺少什么才能逆转这个过程,这意味着我不了解其中的所有内容。 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.这些技术通常用于具有自定义字体的网页,并且与直接在 CSS 文件中给出参考的原始字体文件相比似乎有一些改进。 I am fully aware that the involved fonts are commercial ones and can't be used freely.我清楚所涉及的字体是商业字体,不能随意使用。

That debate is off-topic, stop trolling .那个辩论是题外话,停止拖钓

1) locate the complete font declaration, for example, data:font/opentype;base64,AaBbCcDdEeFf0123456789== 1)找到完整的字体声明,例如data:font/opentype;base64,AaBbCcDdEeFf0123456789==

2) copy the encoded data portion; 2) 复制编码后的数据部分; exclude the leading type declaration and comma.排除前导类型声明和逗号。

Drop this data:font/opentype;base64,删除此data:font/opentype;base64,

You want this: AaBbCcDdEeFf0123456789==你想要这个: AaBbCcDdEeFf0123456789==

3) decode the data and save as a binary encoded file. 3)解码数据并保存为二进制编码文件。 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.使用http://www.motobit.com/util/base64-decoder-encoder.asp选择“从 Base64 字符串解码数据”和“导出到二进制文件”选项。

4) View the file using a plain text editor. 4) 使用纯文本编辑器查看文件。 The first 3 or 4 letters of the file are probably "woff", "otf", or "ttf".文件的前 3 或 4 个字母可能是“woff”、“otf”或“ttf”。 This is your actual file type.这是您的实际文件类型。

Paste data:application/font-woff;base64,d09GRgABAA..... in the browser (ideally Chrome) address bar.在浏览器(最好是 Chrome)地址栏中粘贴data:application/font-woff;base64,d09GRgABAA..... It will download the file, rename the file with proper file extension (eg data:application/font-woff is a .woff , data:application/font-woff2 is a .woff2 , etc...).它将下载文件,使用适当的文件扩展名重命名文件(例如data:application/font-woff.woffdata:application/font-woff2.woff2等...)。 This will work with any font file.这适用于任何字体文件。

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.查看OP的文件,里面有六种字体。 Each one is basically a CSS rule;每一个基本上都是一个 CSS 规则; here's the first one in the example file:这是示例文件中的第一个:

@font-face {
    font-family: "p22-underground-1";
    font-style: normal;
    font-weight: 400;
    src: url("data:font/opentype;base64,d09GRk9...yn4b8C3JEZAA==");
}

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 ).您可以看到它的名称 ( p22-underground-1 )、样式 ( normal )、重量 ( 400 ) 和类型 ( 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.至于将 base64 中的字体解码为二进制文件,您需要取 base64 位(如上所示d09GRk9...yn4b8C3JEZAA== ,注意已删除了 cenre 中的大部分以节省空间)并使用base64 解码器如Motobit或通过编写程序。

If you're on Linux, you can use base64 -d <file> to achieve the same thing.如果您使用的是 Linux,则可以使用base64 -d <file>来实现相同的目的。

If the decoding fails, the base64 string may be also be percent-escaped .如果解码失败,base64 字符串也可能被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. OP 的示例并非如此,但我知道至少有一个站点是这种情况。

You can check for this by looking for percent % symbols in the base64 string.您可以通过在 base64 字符串中查找百分比%符号来检查这一点。 If percent characters are the only non- valid base64 characters then you can try to unescape the string prior to decoding.如果百分比字符是唯一无效的base64 字符,那么您可以尝试在解码之前对字符串进行转义。

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):有一个网站可以让你做到这一点,或者,对于那些在 Linux 上的人,下面显示了一种命令行方法(有很多方法可以做到这一点;这个使用 Perl):

perl -MURI::Escape -lne 'print uri_unescape($_)' < file.b64_escaped > file.b64

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.我在 Ruby 中编写了一个小工具,它使用上述技术获取 url 并将任何嵌入的字体转储到文件中,因此我可以说它们确实有效。

The CSS clearly states the mimetype to be font/opentype ... The font is in OpenType ( .otf ) format. CSS 明确指出 mimetype 为font/opentype opentype ...字体采用 OpenType ( .otf ) 格式。

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 . CSS 文件( Proxma Nova [Mark Simonson Studios] 和P22 Underground [P22 Type Foundry])引用的字体不是免费的 You need to purchase a license to use them legally.您需要购买许可证才能合法使用它们。

You can see that the mimetype is font/opentype , which means the resulting binary should be .otf . 您可以看到mimetype是font/opentype ,这意味着生成的二进制文件应该是.otf

Why, though, would you ever want to decode the font? 但是,为什么你想要解码字体呢? Sounds like you are planning to use that font without permission. 听起来你打算在未经许可的情况下使用该字体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将base64编码的字符串解码为字体文件-Unicode范围 - Decode base64-encoded string to font file - unicode range 内联base64编码的图像或HTTP请求? - Inline base64-encoded images or HTTP request? 使用angularjs将SVG中的xlink:href设置为base64编码的图像 - Set xlink:href in svg with angularjs to base64-encoded image 为什么CSS内联(base64编码)webfonts会延迟呈现? - Why are CSS-inlined (base64-encoded) webfonts rendered with a delay? Tumblr的Base64编码@ font-face - Base64 encoded @font-face for Tumblr 使用数据URI的Base64编码的OpenType字体 - Base64 encoded OpenType font-face using data URI 如何动态应用base64编码的数据uri? - How to apply base64 encoded data uri's dynamically? CSP允许特定:data:font / woff; base64,“someBase64encoded font”,不使用csp:font-src'self'数据: - CSP allow specific: data:font/woff;base64,“someBase64encoded font”, WITHOUT using csp: font-src 'self' data: 带有 base64 编码的 .ttf 字体文件的 favicon.svg 在 Chrome 中不显示文本,在 Firefox 中工作 - favicon.svg with base64 encoded .ttf font file doesn't display text in Chrome, works in Firefox 如何让Chrome在新窗口中将Base64编码的图像另存为png? - How can I make Chrome save a Base64 encoded image as a png within a new window?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM