跳到主要内容
uencoder

如何Implement Verifiable Credentials

Issue, hold, 和验证 cryptographically provable digital credentials using W3C Verifiable Credentials 和 Decentralized Identifiers ().

问题

你需要prove attributes 关于 entity (age, degree, membership) 无 relying 开中心数据库该 verifier queries. Verifiable Credentials (VCs) let holder 存在 cryptographically signed credential 该任何 verifier 能够验证无 contacting issuer.

前置条件

  • Understanding 的 digital signatures 和公共键 infrastructure
  • 熟悉JSON-LD 和 linked 数据 proofs
  • Knowledge 的 Decentralized Identifiers ()

步骤

  1. 1. Establish DIDs and verification keys

    Create Decentralized Identifiers (DIDs) for the issuer, holder, and verifier. Each DID resolves to a DID Document containing verification methods (public keys) and service endpoints. The issuer generates a signing key pair (Ed25519 or ECDSA P-256) and publishes the public key in its DID Document. Use a DID method like did:web (DNS-based) or did:key (self-contained). Use the RSA tool and ECC tools to generate key pairs and the JSON validator to verify DID Document format.

    输入
    entity: University | DID method: did:web
    输出
    DID: did:web:university.example | DID Document with Ed25519 verification key
  2. 2. Issue a verifiable credential

    The issuer creates a credential containing: @context (JSON-LD contexts), type (e.g., UniversityDegreeCredential), issuer (DID), issuanceDate, expirationDate, credentialSubject (holder DID + claims), and proof (digital signature). Sign the credential using the issuer's private key with a Linked Data Proof (Ed25519Signature2018 or JsonWebSignature2020). The signature covers the canonicalized credential (using RDF Dataset Canonicalization). Use the JSON formatter and hash tools for canonicalization.

    输入
    claims: {degree: BSc Computer Science, holder: did:web:alice} | issuer key: Ed25519
    输出
    VC: {credential..., proof: {type: Ed25519Signature2018, created: 2026-01-01, verificationMethod: did:web:univ#key-1, proofValue: ...}}
  3. 3. Create and present a verifiable presentation

    The holder creates a Verifiable Presentation containing the credential(s) they want to present, signed with their own key to prove they are the subject. Optionally use selective disclosure (BBS+ signatures) to reveal only specific attributes, or zero-knowledge proofs to prove properties (age > 18) without revealing the exact value. The presentation is sent to the verifier. Use the JWT encode tool to create JWT-VC representations as an alternative to JSON-LD.

    输入
    credential: UniversityDegreeVC | holder key: Alice's Ed25519
    输出
    VP: {verifiableCredential: [VC], proof: {holder signature proving possession}}
  4. 4. Verify the credential and check revocation

    The verifier: (1) resolves the issuer DID to get the public key, (2) canonicalizes the credential (minus proof) and verifies the signature, (3) checks issuanceDate and expirationDate, (4) verifies the holder's signature on the presentation, (5) checks revocation status via the issuer's revocation method (StatusList2021, accumulator, or revocation registry). If all checks pass, the credential is authentic and valid. Use the hash-compare and JWT tools for verification.

    输入
    VP from Alice | issuer DID: did:web:university.example
    输出
    verified: signature ✓ | dates ✓ | not revoked ✓ | holder ✓ -> CREDENTIAL VALID

预期结果

verifiable credentials 系统 where issuers sign credentials, holders 存在它们具有证明的 possession, 和 verifiers 验证它们 cryptographically 无 contacting issuer.

常见错误

Not canonicalizing JSON-LD before signing
JSON-LD can have multiple serializations for the same data. Use RDF Dataset Canonicalization (URDNA2015) to produce a canonical form before signing and verifying. Without this, signatures may break on re-serialization.
Not checking credential expiration and revocation
A valid signature doesn't mean a credential is current. Always check issuanceDate, expirationDate, and revocation status. Implement StatusList2021 for efficient revocation.
Confusing JWT-VC with JSON-LD-VC
These are two different encoding formats for VCs. JWT-VC packs the credential into a JWT; JSON-LD-VC uses linked data proofs. Choose one and be consistent. Both are W3C-compliant.

排障指引

  • If signature verification fails, check that the canonicalization algorithm matches (URDNA2015), the @context resolves correctly, and the verification method in the proof matches the issuer's current key.
  • For selective disclosure, use BBS+ signatures instead of Ed25519. BBS+ allows proving credential possession while revealing only chosen attributes.
  • If DID resolution fails, ensure the DID method is supported and the DID Document is accessible at the expected location (e.g., https://university.example/.well-known/did.json for did:web).

安全限制

  • Verifiable credentials prove the issuer signed the data — they do not verify the issuer's claims are true. Trust in the issuer is separate from cryptographic verification.
  • All signature creation and verification happen locally; no credential data is sent to the issuer during verification.
  • Holder binding requires the verifier to challenge the holder to prove possession of the key linked to the credential subject DID.

相关工具

JWT 解码器
解码并检查 JWT 头部、载荷和时间声明及过期状态。免费、隐私优先、100% 纯客户端运行。本地解析不视为服务端验签。支持 HS256/RS256 等算法头部解析、exp/iat/nbf 时间声明展示,并标注 EXPIRED/NOT YET VALID/VALID 状态。
工具
JWT 编码器
使用 HS256 编码 JWT。免费、隐私优先、100% 纯客户端运行。不用于服务端验签。
工具
哈希计算器
计算 MD5、SHA-1、SHA-256 或 SHA-512 哈希,支持十六进制或 Base64 输出。免费、隐私、100% 客户端运行。SHA-256/512 基于 Web Crypto API,MD5 基于 spark-md5,适用于校验和、完整性验证、指纹识别等场景。MD5 与 SHA-1 已不适用于安全场景。
工具
SHA-3 / Keccak 哈希计算器
计算 SHA-3(224/256/384/512)和 Keccak-256 哈希。免费、隐私、100% 客户端运行。
工具
HMAC 生成器
使用 SHA-1/256/512 生成 HMAC(哈希消息认证码)。免费、隐私优先、100% 纯客户端运行。
工具
JSON 验证器
验证 JSON 并按行列定位语法错误。免费、隐私本地化、100% 客户端运行。
工具
JSON 格式化器
在线格式化、压缩或排序 JSON。免费、隐私本地化、100% 客户端运行。支持 2 空格缩进美化、单行压缩、递归按键排序,遇到语法错误会精确定位行号与列号,适合调试 API 响应、配置文件与数据交换格式。
工具
Base64 编码器
将文本或二进制数据编码为 Base64。免费、隐私优先、100% 纯客户端运行。支持 UTF-8、ASCII、Latin1、UTF-16LE 字符集,可处理多语言文本与二进制内容,结果可直接用于 Data URI、邮件附件、JWT 等场景。
工具
Base64 解码器
将 Base64 数据解码为可读文本。免费、隐私优先、100% 纯客户端运行。支持 UTF-8、ASCII、Latin1、UTF-16LE 字符集,可处理 Data URI、JWT 载荷、邮件附件等场景,遇到非法输入会明确报错而非静默产生乱码。
工具
URL 解析器
将 URL 解析为各组成部分:协议、主机、路径、查询、哈希、端口、用户名和密码。免费、隐私、100% 客户端运行。
工具

相关词条

参考链接