为文件(或文件集)生成 base64 编码的 SHA512 摘要
适用于 Tablet OS 的 BlackBerry WebWorks SDK 构建工具会生成一个存档,其中包含文件和一个 MANIFEST.MF,其中包含每个文件的条目和一个 Base64 编码的 SHA512 摘要。但是有一个bug,构建中文件过多会导致构建失败。我正在尝试弄清楚如何自己生成相同的信息。
下面的示例来自 MANIFEST.MF,它包含文件名和摘要。但是,base64 变体使用 _
代替 /
,使用 -
代替 +
,并且没有尾随 ==
用于填充。
Archive-Asset-Name: air/XX/IMG_0999.jpg
Archive-Asset-SHA-512-Digest: YI_KXWjpJwwsi5MDQPeBQc9SVi-bH6zYq5PgBD3jQiqHu-r-5Hv8A0yh_y5j2T9MpYZ5TVMW4JXHSXNYmpV1tA
我运行 Windows 7,但安装了 GIT,因此我将 MINGW32 作为 bash shell。我发现了 openssl 和 tr 命令的管道组合,但它似乎有点混乱。
openssl dgst -sha512 -binary IMG_0999.gif | openssl enc -base64 | tr '+' '-' | tr '/' '_' | tr -d '=' | tr -d '\n'
有没有更好的方法来生成这个摘要?
最终,我将不得不对目录树中的所有图像进行处理。我希望有一个脚本解决方案,而不必编写程序。第二个问题是如何为目录中的所有文件生成清单语法(递归地)。这是包含上述命令的 bash shell 脚本吗?由于我以前没有编写过 shell 脚本,所以这里的任何指针都会受到赞赏。
The BlackBerry WebWorks SDK for Tablet OS build tool generates an archive that contains the files and a MANIFEST.MF with entry for each file and a base64 encoded SHA512 digest. However, there is a bug that too many files in the build will cause a build failure. I am trying to figure out how to generate that same information myself.
The example below comes from the MANIFEST.MF
and it contains the filename and digest. However, the base64 variant uses _
instead of /
and -
instead of +
and has no trailing ==
for padding.
Archive-Asset-Name: air/XX/IMG_0999.jpg
Archive-Asset-SHA-512-Digest: YI_KXWjpJwwsi5MDQPeBQc9SVi-bH6zYq5PgBD3jQiqHu-r-5Hv8A0yh_y5j2T9MpYZ5TVMW4JXHSXNYmpV1tA
I running Windows 7, but have GIT installed so I have MINGW32 as a bash shell. I found this piped combination of openssl and tr commands but it seems a bit of a kludge.
openssl dgst -sha512 -binary IMG_0999.gif | openssl enc -base64 | tr '+' '-' | tr '/' '_' | tr -d '=' | tr -d '\n'
Is there a better way to generate this digest?
Eventually, I will have to do for all the images in a directory tree. I was hoping for a script solution instead of having to write a program. A second question is how to generate that manifest syntax for all files in a directory (recursively). Would this be a bash shell script encompassing the above command? Any pointers here are appreciated since I haven't written a shell script before.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过组合一些内容来缩短命令:
对于树中的所有文件,例如:
You can shorten your command by combining some things:
For all files in a tree, something like:
Dennis Williamson 的解决方案让我继续前进,但是安装的 tr 版本 (2.0) 确实喜欢多字符语法。此外,
xargs
版本 (4.1) 不喜欢-I
选项。然而,它让我开始了,这才是重要的。这就是我最终得到的结果:并生成以下内容(更改图像名称以保护无辜者)
我仍然需要调整名称,使其不带有
./
前缀,但那是另一天的事了。Dennis Williamson's solution got me going but the
tr
version (2.0) that is installed did like that multiple character syntax. Also, thexargs
version (4.1) didn't like the-I
option. However, it got me started and that is what matters. Here is what I ended up with:and that generates the following (images names changed to protect the innocent)
I still need to tweak the name to not be prefixed with
./
but that is for another day.