Calculating CRC32 checksum of a file

14,235

Have you looked at Digest::CRC? From the documentation: "It contains wrapper functions with the correct parameters for CRC-CCITT, CRC-16, CRC-32 and CRC-64, as well as the CRC used in OpenPGP's ASCII-armored checksum."

use strict;
use warnings;
use Digest::CRC;

my $ctx = Digest::CRC->new( type => 'crc32' );

open my $fh, '<:raw', $ARGV[0] or die $!;
$ctx->addfile(*$fh);
close $fh;

print $ctx->hexdigest, "\n";

Command-line usage: perl script.pl inFile

Hope this helps!

Share:
14,235
Naveen Gamage
Author by

Naveen Gamage

love to make new things...

Updated on June 13, 2022

Comments

  • Naveen Gamage
    Naveen Gamage almost 2 years

    I'm trying to calculate CRC32 check sum of a file to use with this module Mod_zip, I tried to do this with PHP but unfortunately failed, even if passed won't be efficient for larger files.

    I also tried linux cksum command but it calculates CRC checksum of the file.

    I found that perl on linux can be used to calculate CRC32 of a file, if this is possible I could use shell_exec to import the output onto my PHP application, how can I do this?