Search code examples
shellgnupg

GNU Privacy Guard(GPG) in Shell/bash


I was trying to do do some more shell scripting in the last few days.

where I am trying to calculate the value of a function. To start with I get an

echo "blah"
read blub

md5=`md5sum $blub | cut -d ' ' -f 1`
echo $md5

echo "secretkey"
read $SK

For example, If get the values like that.
Is it possible at-all to do a calculation withGPG like this

GPG(VALUE1,VALUE2) in my case it is GPG(md5,sk)

Later on I would like to take a modular function over that value. Which is possible via the shell script.

If its possible , May I ask how is it possible to do in GPG. or is there any other better public generating algorithm that can do this?

Thanks!


Solution

  • If I understand you correctly, you are trying to obtain a digest (hash, checksum) of the MD5 + secret key pair (much like the MD5 is a digest of the blub).

    In any case, GPG won't help you here. It's mostly a tool for encryption and signing with PGP. It can do symmetric encryption of files as well but AFAICS it doesn't do stand-alone digests, and certainly doesn't do them in decimal form.

    The simplest solution seems to be using one of the common shell checksumming tools which actually have numeric output — for example cksum.

    Those tools take only a single blob as an argument, so you probably want to simply concatenate the input

    I think a working example would be:

    gpg=$(echo "$md5$sk" | cksum | cut -d' ' -f1)
    

    Then gpg will contain some decimal value, unique for each md5 + secret key pair.