Multiformats CID implementation for .NET.
$ dotnet add package NetCidNetCid is a C# (net10.0) implementation of the multiformats CID specification.
ToV0, ToV1)base58btc (z)base32 lower/upper (b / B)base36 lower/upper (k / K)raw, dag-pb, dag-cbor, etc.)dotnet add package NetCid
using NetCid;
using System.Text;
// Parse existing CIDs
var v0 = Cid.Parse("QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n");
var v1 = Cid.Parse("bafkreidon73zkcrwdb5iafqtijxildoonbwnpv7dyd6ef3qdgads2jc4su");
// Convert versions
var v0AsV1 = v0.ToV1();
var v1AsV0 = v0AsV1.ToV0();
// Build from content bytes
var content = Encoding.UTF8.GetBytes("hello world");
var cid = Cid.FromContent(content, codec: Multicodec.Raw, hashCode: MultihashCode.Sha2_256);
// Serialize
string text = cid.ToString(); // CIDv1 defaults to base32 lower
byte[] bytes = cid.ToByteArray();
Implementation follows the CID spec behavior, including:
dag-pb + sha2-256(32)<cidv1-varint><codec-varint><multihash>2 and 3 are treated as reserved/invalidParsing APIs enforce default size limits to reduce memory-pressure risk from untrusted input:
Cid.DefaultMaxInputStringLengthCid.DefaultMaxInputByteLengthMultibase.DefaultMaxInputLengthOverloads on parse/decode methods let callers provide custom limits when needed.
References:
dotnet restore NetCid.sln
dotnet build NetCid.sln -c Release
dotnet test NetCid.Tests/NetCid.Tests.csproj -c Release
dotnet test NetCid.IntegrationTests/NetCid.IntegrationTests.csproj -c Release
Reference examples are available under examples/ and mirror the js-multiformats example set:
examples/cid-interfaceexamples/multicodec-interfaceexamples/multihash-interfaceexamples/block-interfaceSee examples/README.md for run commands.
See contributors.md for contributor workflow, quality checklist, and PR expectations.
.github/workflows/ci.yml.github/workflows/security.yml, .github/workflows/codeql.yml.github/workflows/release.ymlrelease.yml pushes packages when a tag like v1.2.3 is pushed (or manual dispatch) and requires NUGET_API_KEY repository secret.
SECURITY.mdSECURITY_AUDIT.md