bash - Generating a base64 encoded SHA512 digest for a file (or set of files) -
the blackberry webworks sdk tablet os build tool generates archive contains files , manifest.mf entry each file , base64 encoded sha512 digest. however, there bug many files in build cause build failure. trying figure out how generate same information myself.
the example below comes manifest.mf
, contains filename , digest. however, base64 variant uses _
instead of /
, -
instead of +
, has no trailing ==
padding.
archive-asset-name: air/xx/img_0999.jpg archive-asset-sha-512-digest: yi_kxwjpjwwsi5mdqpebqc9svi-bh6zyq5pgbd3jqiqhu-r-5hv8a0yh_y5j2t9mpyz5tvmw4jxhsxnympv1ta
i running windows 7, have git installed have mingw32 bash shell. found piped combination of openssl , tr commands seems bit of kludge.
openssl dgst -sha512 -binary img_0999.gif | openssl enc -base64 | tr '+' '-' | tr '/' '_' | tr -d '=' | tr -d '\n'
is there better way generate digest?
eventually, have images in directory tree. hoping script solution instead of having write program. second question how generate manifest syntax files in directory (recursively). bash shell script encompassing above command? pointers here appreciated since haven't written shell script before.
you can shorten command combining things:
openssl dgst -sha512 -binary img_0999.gif | openssl enc -base64 | tr '+/' '-_' | tr -d '=\n'
for files in tree, like:
find . -type f -name '*.gif' -print0 | xargs -0 -i % sh -c 'openssl dgst -sha512 -binary "$(basename "$1")" | openssl enc -base64 | tr "+/" "-_" | tr -d "=\n" > "$1.sum"' _ $1
Comments
Post a Comment