[{"data":1,"prerenderedAt":460},["ShallowReactive",2],{"blog:2007:calculating-crc-64-in-c-and-net":3,"blogMore-Development":446,"comments-calculating-crc-64-in-c-and-net":459},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":11,"tags":12,"excerpt":16,"body":40,"_type":437,"_id":438,"_source":439,"_file":440,"_stem":441,"_extension":442,"url":443,"wordCount":444,"minutes":145,"commentCount":445},"/blog/2007/calculating-crc-64-in-c-and-net","2007",false,"en","Calculating CRC-64 in C# and .NET","Seeing how the CRC-32 C# class I posted some time ago continues to get lots of Google hits I thought I’d post a CRC-64 version which will no doubt be far less popular being the more limited use. Again, do not use this as a secure message signature, it’s really for backward compatibility with legacy systems.","2007-11-19T12:53:32+00:00","Development",[13,14,15],".NET","C#","hashing",{"type":17,"children":18},"root",[19,35],{"type":20,"tag":21,"props":22,"children":23},"element","p",{},[24,27,29,31,33],{"type":25,"value":26},"text","Seeing how the ",{"type":25,"value":28},"CRC-32 C# class I posted some time ago",{"type":25,"value":30}," continues to get lots of Google hits I thought I’d post a ",{"type":25,"value":32},"CRC-64",{"type":25,"value":34}," version which will no doubt be far less popular being the more limited use. Again, do not use this as a secure message signature, it’s really for backward compatibility with legacy systems.",{"type":20,"tag":21,"props":36,"children":37},{},[38],{"type":25,"value":39},"This is the ISO-3309 version of CRC-64 algorithm. It is not compatible with the ECMA-182 algorithm.",{"type":17,"children":41,"toc":435},[42,61,69,86,91,406,420,429],{"type":20,"tag":21,"props":43,"children":44},{},[45,46,52,53,60],{"type":25,"value":26},{"type":20,"tag":47,"props":48,"children":50},"a",{"href":49},"/blog/2006/calculating_crc32_in_c_and_net/",[51],{"type":25,"value":28},{"type":25,"value":30},{"type":20,"tag":47,"props":54,"children":58},{"href":55,"rel":56},"https://www.cesnet.cz/doc/techzpravy/2005/crc64/",[57],"nofollow",[59],{"type":25,"value":32},{"type":25,"value":34},{"type":20,"tag":62,"props":63,"children":64},"blockquote",{},[65],{"type":20,"tag":21,"props":66,"children":67},{},[68],{"type":25,"value":39},{"type":20,"tag":62,"props":70,"children":71},{},[72],{"type":20,"tag":21,"props":73,"children":74},{},[75,77,84],{"type":25,"value":76},"GitHub has the ",{"type":20,"tag":47,"props":78,"children":81},{"href":79,"rel":80},"https://github.com/damieng/DamienGKit/blob/master/CSharp/DamienG.Library/Security/Cryptography/Crc64.cs",[57],[82],{"type":25,"value":83},"latest version of Crc64",{"type":25,"value":85},".",{"type":20,"tag":21,"props":87,"children":88},{},[89],{"type":25,"value":90},"To use this or the CRC-32 class to compute the hash for a file simply:",{"type":20,"tag":92,"props":93,"children":98},"pre",{"className":94,"code":95,"language":96,"meta":97,"style":97},"language-csharp shiki shiki-themes everforest-light dracula","Crc64 crc64 = new Crc64();\nString hash = String.Empty;\n\nusing (FileStream fs = File.Open(\"c:\\\\myfile.txt\", FileMode.Open))\n  foreach (byte b in crc64.ComputeHash(fs)) hash += b.ToString(\"x2\").ToLower();\n\nConsole.WriteLine(\"CRC-64 is {0}\", hash);\n","csharp","",[99],{"type":20,"tag":100,"props":101,"children":102},"code",{"__ignoreMap":97},[103,143,177,187,272,362,370],{"type":20,"tag":104,"props":105,"children":108},"span",{"class":106,"line":107},"line",1,[109,115,121,127,133,138],{"type":20,"tag":104,"props":110,"children":112},{"style":111},"--shiki-default:#3A94C5;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[113],{"type":25,"value":114},"Crc64",{"type":20,"tag":104,"props":116,"children":118},{"style":117},"--shiki-default:#5C6A72;--shiki-dark:#F8F8F2",[119],{"type":25,"value":120}," crc64 ",{"type":20,"tag":104,"props":122,"children":124},{"style":123},"--shiki-default:#F57D26;--shiki-dark:#FF79C6",[125],{"type":25,"value":126},"=",{"type":20,"tag":104,"props":128,"children":130},{"style":129},"--shiki-default:#F85552;--shiki-dark:#FF79C6",[131],{"type":25,"value":132}," new",{"type":20,"tag":104,"props":134,"children":135},{"style":111},[136],{"type":25,"value":137}," Crc64",{"type":20,"tag":104,"props":139,"children":140},{"style":117},[141],{"type":25,"value":142},"();\n",{"type":20,"tag":104,"props":144,"children":146},{"class":106,"line":145},2,[147,152,157,161,166,172],{"type":20,"tag":104,"props":148,"children":149},{"style":111},[150],{"type":25,"value":151},"String",{"type":20,"tag":104,"props":153,"children":154},{"style":117},[155],{"type":25,"value":156}," hash ",{"type":20,"tag":104,"props":158,"children":159},{"style":123},[160],{"type":25,"value":126},{"type":20,"tag":104,"props":162,"children":163},{"style":117},[164],{"type":25,"value":165}," String.",{"type":20,"tag":104,"props":167,"children":169},{"style":168},"--shiki-default:#35A77C;--shiki-dark:#F8F8F2",[170],{"type":25,"value":171},"Empty",{"type":20,"tag":104,"props":173,"children":174},{"style":117},[175],{"type":25,"value":176},";\n",{"type":20,"tag":104,"props":178,"children":180},{"class":106,"line":179},3,[181],{"type":20,"tag":104,"props":182,"children":184},{"emptyLinePlaceholder":183},true,[185],{"type":25,"value":186},"\n",{"type":20,"tag":104,"props":188,"children":190},{"class":106,"line":189},4,[191,196,201,206,211,215,220,226,231,237,243,249,254,258,263,267],{"type":20,"tag":104,"props":192,"children":193},{"style":129},[194],{"type":25,"value":195},"using",{"type":20,"tag":104,"props":197,"children":198},{"style":117},[199],{"type":25,"value":200}," (",{"type":20,"tag":104,"props":202,"children":203},{"style":111},[204],{"type":25,"value":205},"FileStream",{"type":20,"tag":104,"props":207,"children":208},{"style":117},[209],{"type":25,"value":210}," fs ",{"type":20,"tag":104,"props":212,"children":213},{"style":123},[214],{"type":25,"value":126},{"type":20,"tag":104,"props":216,"children":217},{"style":117},[218],{"type":25,"value":219}," File.",{"type":20,"tag":104,"props":221,"children":223},{"style":222},"--shiki-default:#8DA101;--shiki-dark:#50FA7B",[224],{"type":25,"value":225},"Open",{"type":20,"tag":104,"props":227,"children":228},{"style":117},[229],{"type":25,"value":230},"(",{"type":20,"tag":104,"props":232,"children":234},{"style":233},"--shiki-default:#8DA101;--shiki-dark:#E9F284",[235],{"type":25,"value":236},"\"",{"type":20,"tag":104,"props":238,"children":240},{"style":239},"--shiki-default:#8DA101;--shiki-dark:#F1FA8C",[241],{"type":25,"value":242},"c:",{"type":20,"tag":104,"props":244,"children":246},{"style":245},"--shiki-default:#DFA000;--shiki-dark:#FF79C6",[247],{"type":25,"value":248},"\\\\",{"type":20,"tag":104,"props":250,"children":251},{"style":239},[252],{"type":25,"value":253},"myfile.txt",{"type":20,"tag":104,"props":255,"children":256},{"style":233},[257],{"type":25,"value":236},{"type":20,"tag":104,"props":259,"children":260},{"style":117},[261],{"type":25,"value":262},", FileMode.",{"type":20,"tag":104,"props":264,"children":265},{"style":168},[266],{"type":25,"value":225},{"type":20,"tag":104,"props":268,"children":269},{"style":117},[270],{"type":25,"value":271},"))\n",{"type":20,"tag":104,"props":273,"children":275},{"class":106,"line":274},5,[276,281,285,291,296,301,306,311,316,321,326,331,335,339,344,348,353,358],{"type":20,"tag":104,"props":277,"children":278},{"style":129},[279],{"type":25,"value":280},"  foreach",{"type":20,"tag":104,"props":282,"children":283},{"style":117},[284],{"type":25,"value":200},{"type":20,"tag":104,"props":286,"children":288},{"style":287},"--shiki-default:#3A94C5;--shiki-dark:#FF79C6",[289],{"type":25,"value":290},"byte",{"type":20,"tag":104,"props":292,"children":293},{"style":117},[294],{"type":25,"value":295}," b ",{"type":20,"tag":104,"props":297,"children":298},{"style":129},[299],{"type":25,"value":300},"in",{"type":20,"tag":104,"props":302,"children":303},{"style":117},[304],{"type":25,"value":305}," crc64.",{"type":20,"tag":104,"props":307,"children":308},{"style":222},[309],{"type":25,"value":310},"ComputeHash",{"type":20,"tag":104,"props":312,"children":313},{"style":117},[314],{"type":25,"value":315},"(fs)) hash ",{"type":20,"tag":104,"props":317,"children":318},{"style":123},[319],{"type":25,"value":320},"+=",{"type":20,"tag":104,"props":322,"children":323},{"style":117},[324],{"type":25,"value":325}," b.",{"type":20,"tag":104,"props":327,"children":328},{"style":222},[329],{"type":25,"value":330},"ToString",{"type":20,"tag":104,"props":332,"children":333},{"style":117},[334],{"type":25,"value":230},{"type":20,"tag":104,"props":336,"children":337},{"style":233},[338],{"type":25,"value":236},{"type":20,"tag":104,"props":340,"children":341},{"style":239},[342],{"type":25,"value":343},"x2",{"type":20,"tag":104,"props":345,"children":346},{"style":233},[347],{"type":25,"value":236},{"type":20,"tag":104,"props":349,"children":350},{"style":117},[351],{"type":25,"value":352},").",{"type":20,"tag":104,"props":354,"children":355},{"style":222},[356],{"type":25,"value":357},"ToLower",{"type":20,"tag":104,"props":359,"children":360},{"style":117},[361],{"type":25,"value":142},{"type":20,"tag":104,"props":363,"children":365},{"class":106,"line":364},6,[366],{"type":20,"tag":104,"props":367,"children":368},{"emptyLinePlaceholder":183},[369],{"type":25,"value":186},{"type":20,"tag":104,"props":371,"children":373},{"class":106,"line":372},7,[374,379,384,388,392,397,401],{"type":20,"tag":104,"props":375,"children":376},{"style":117},[377],{"type":25,"value":378},"Console.",{"type":20,"tag":104,"props":380,"children":381},{"style":222},[382],{"type":25,"value":383},"WriteLine",{"type":20,"tag":104,"props":385,"children":386},{"style":117},[387],{"type":25,"value":230},{"type":20,"tag":104,"props":389,"children":390},{"style":233},[391],{"type":25,"value":236},{"type":20,"tag":104,"props":393,"children":394},{"style":239},[395],{"type":25,"value":396},"CRC-64 is {0}",{"type":20,"tag":104,"props":398,"children":399},{"style":233},[400],{"type":25,"value":236},{"type":20,"tag":104,"props":402,"children":403},{"style":117},[404],{"type":25,"value":405},", hash);\n",{"type":20,"tag":21,"props":407,"children":408},{},[409,411,418],{"type":25,"value":410},"While writing this I considered if I should implement some more advanced hashing algorithms missing from .NET like RIPEMD320 only to stumble across ",{"type":20,"tag":47,"props":412,"children":415},{"href":413,"rel":414},"https://www.bouncycastle.org/csharp/index.html",[57],[416],{"type":25,"value":417},"The Legion of Bouncy Castles C# Cryptography APIs",{"type":25,"value":419}," which also includes generating PKCS #12 files and a whole bunch of encryption algorithms (but nothing as weak as CRC-64 ;-)",{"type":20,"tag":21,"props":421,"children":422},{},[423],{"type":20,"tag":424,"props":425,"children":426},"em",{},[427],{"type":25,"value":428},"[)amien",{"type":20,"tag":430,"props":431,"children":432},"style",{},[433],{"type":25,"value":434},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":97,"searchDepth":145,"depth":145,"links":436},[],"markdown","content:blog:2007:calculating-crc-64-in-c-and-net.md","content","blog/2007/calculating-crc-64-in-c-and-net.md","blog/2007/calculating-crc-64-in-c-and-net","md","/blog/2007/calculating-crc-64-in-c-and-net/",243,0,[447,451,455],{"title":448,"date":449,"url":450},"HTML5 Video Cheatsheet: Optimizing videos for the web","2025-12-05T00:00:00Z","/blog/2025/html5-video-cheatsheet/",{"title":452,"date":453,"url":454},"Transactions in the MongoDB EF Core Provider","2025-10-25","/blog/2025/mongodb-explicit-transactions/",{"title":456,"date":457,"url":458},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","/blog/2025/mongodb-queryable-encryption/",[],1779264589773]