in reply to Perl SHA256

...Any suggestions besides installing the module...

You don't need to install a module because Digest::SHA is a core perl module.

$ perl -E 'use Digest::SHA "sha256_hex"; say sha256_hex("foobar")' c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2 $ perl -E 'use Digest::SHA "sha256_hex"; say sha256_hex("foobar\n")' aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f

Anyway, maybe you are asking for advice about shelling out to programs more than advice about calculating SHA digests. You didn't do a very good job at reducing your code to the simplest example, but when I take your code and replace the for loop with $EMAIL_LIST = '"130000000640","foobar"' it works just fine (assuming you are fine with the SHA256 sum including the newline character, which seems pretty wrong to me). So, if your program is broken it is probably something else causing the problem, not the part where you shell out to openssl.

Here are other random points of advice that apply to what I see here:

Replies are listed 'Best First'.
Re^2: Perl SHA256
by Anonymous Monk on Feb 14, 2023 at 02:02 UTC
      You don't need to install a module because Digest::SHA is a core perl module.
      $ perl -E 'use Digest::SHA "sha256_hex"; say sha256_hex("foobar")'
      c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2

    Perl also comes with the core utility shasum:

    perl -e 'print "foobar"' | shasum -a 256
    c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2
      None of the reply response examples work for emails.. It only works f +or "foobar".. Why are the online links and Linux different? How do +I get perl to give me what both Linux/Online return? https://xorbin.com/tools/sha256-hash-calculator joe.smith@aol.com --> 4d1612632ab95a0dec3d27f521d2b91cabe9e72a6b1ecdb8 +784e1ed6f3a93604 perl -E 'use Digest::SHA "sha256_hex"; say sha256_hex("joe.smith@aol.c +om")' --> 4ea2142392947d467539285b3c6e98f073d9d85910f2a1d535f86a95358 +ab9dd perl -E 'use Digest::SHA "sha256_hex"; say sha256_hex("joe.smith@aol.c +om")' --> 4ea2142392947d467539285b3c6e98f073d9d85910f2a1d535f86a9535 +8ab9dd perl -e 'print "joe.smith@aol.com"' | shasum -a 256 --> 4ea2142392947d +467539285b3c6e98f073d9d85910f2a1d535f86a95358ab9dd - https://codebeautify.org/sha256-hash-generator joe.smith@aol.com --> 4d1612632ab95a0dec3d27f521d2b91cabe9e72a6b1ecdb8 +784e1ed6f3a93604 Linux echo "joe.smith@aol.com" | shasum -a 256 --> d6220b1b3a4a67731d5ca82c1 +01cec2c30069ed674c04576e78322c1fbca1c92 - Linux echo joe.smith@aol.com | shasum -a 256 --> d6220b1b3a4a67731d5ca82c101 +cec2c30069ed674c04576e78322c1fbca1c92 - Linux printf %s "joe.smith@aol.com" | sha256sum --> 4d1612632ab95a0dec3d27f5 +21d2b91cabe9e72a6b1ecdb8784e1ed6f3a93604 - Linux echo -n "joe.smith@aol.com" | openssl dgst -sha256 --> (stdin)= 4d1612 +632ab95a0dec3d27f521d2b91cabe9e72a6b1ecdb8784e1ed6f3a93604

        Works fine for me with the proper quoting.

        $ echo -n joe.smith@aol.com | sha256sum 4d1612632ab95a0dec3d27f521d2b91cabe9e72a6b1ecdb8784e1ed6f3a93604 - $ perl -MDigest::SHA=sha256_hex -E 'say sha256_hex(q/joe.smith@aol.com +/)' 4d1612632ab95a0dec3d27f521d2b91cabe9e72a6b1ecdb8784e1ed6f3a93604

        Your problem is that you are using double quotes which interpolate and using neither strict nor warnings which would have drawn your attention to the undeclared and uninitialised array.

        $ perl -wE 'use Digest::SHA "sha256_hex"; say sha256_hex("joe.smith@ao +l.com")' Possible unintended interpolation of @aol in string at -e line 1. Name "main::aol" used only once: possible typo at -e line 1. 4ea2142392947d467539285b3c6e98f073d9d85910f2a1d535f86a95358ab9dd $ perl -Mstrict -wE 'use Digest::SHA "sha256_hex"; say sha256_hex("joe +.smith@aol.com")' Possible unintended interpolation of @aol in string at -e line 1. Global symbol "@aol" requires explicit package name (did you forget to + declare "my @aol"?) at -e line 1. Execution of -e aborted due to compilation errors.

        Always use strict and warnings. Always.


        🦛

        Please, don't use the code tag for normal text.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        Linux
        echo joe.smith@aol.com | shasum -a 256 --> d6220b1b3a4a67731d5ca82c101cec2c30069ed674c04576e78322c1fbca1c92  -
        
        Use -n to prevent echo from including invisible newline character:
        echo -n joe.smith@aol.com | shasum -a 256
        4d1612632ab95a0dec3d27f521d2b91cabe9e72a6b1ecdb8784e1ed6f3a93604  -