CMD批处理-将文件编码为以64为基数,并修剪字符和换行 [英] CMD batch - encode file to base 64 and trim characters and new line

查看:151
本文介绍了CMD批处理-将文件编码为以64为基数,并修剪字符和换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 将文件转换为base 64-使用certutil命令,这是base 64的内容看起来像(B64.txt)的样子:

  1. 修剪base 64-基本上,我要删除 ----- BEGIN证书----- ----- END证书----- 这部分是完成,剩下的唯一事情是修剪换行符以形成一个base64底线,因为我会将其传递给请求有效负载.
  1. Trim the base 64 - basically, I want to remove -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- this part is done, the only thing left is trim the newline characters to make a one liner of base64, because I will be passing this to a request payload.


这是我到目前为止所做的:


This is what I did so far:

@ECHO OFF 
cd /filePath
certutil -encode sample.pdf B64.txt
type B64.txt | find /V "-----BEGIN CERTIFICATE-----" | find /V "-----END CERTIFICATE-----" > B64.txt

我的问题是:

  1. 使用命令查找/V * 我如何定义换行符并将其删除?

  1. Using the command find /V* how can I define the new line characters and remove them?

有没有更有效的方法?

是否可以在不将base 64分配为变量的情况下完成此操作?事实证明,变量的限制只有9000个字符左右,而我转换的基数64通常有70,000个字符.

Can this also be done without assigning the base 64 as a variable? It turns out that the limit for variables is only around 9000 characters, and the base 64 I convert normally has 70,000 characters.

推荐答案

有一个使用CERTUTIL的未记录功能的非常简单的解决方案.您可以使用
-ENCODEHEX动词末尾采用无证格式,可直接在一行上直接获得所需的base 64输出,而无需任何标题.

There is a really simple solution using undocumented features of CERTUTIL. You can use the
-ENCODEHEX verb with an undocumented format at the end to directly get your desired output of base 64 all on one line without any headers.

certutil -encodehex -f sample.pdf B64.txt 0x40000001

请参阅DosTips 更多使用certutil的技巧欲获得更多信息.尤其请查看第4篇以获取详细信息所有格式选项的说明.

See the DosTips More Tricks with certutil thread for more information. Especially look at this 4th post for a detailed explanation of all the format options.

这篇关于CMD批处理-将文件编码为以64为基数,并修剪字符和换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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