DICOM Basics using Java - Digital Signatures
Introduction
This is part of my series of articles on the DICOM standard. In this tutorial, we'll explore DICOM digital signatures, which provide cryptographic assurance of data integrity, authentication, and non-repudiation for medical imaging data.
Digital signatures are essential for regulatory compliance (HIPAA), legal requirements, and ensuring that diagnostic images haven't been tampered with.
Prerequisites
Before you begin, ensure you have the following:
- Java JDK installed (Java 8 or later)
- PixelMed Java DICOM Toolkit
- Understanding of X.509 certificates and PKI concepts
- You can find all the code demonstrated in this tutorial on GitHub here
“The only thing we know for certain is that nothing is certain.” ~ Pliny the Elder
The Theory Behind Digital Signatures
Digital signatures in DICOM implement public key cryptography to solve the fundamental problem of trust in distributed systems: how can a physician in one facility trust that an image from another facility hasn't been altered?
The Cryptographic Foundation
DICOM signatures rely on asymmetric cryptography, specifically:
- Hash Functions: A cryptographic hash (SHA-256) creates a fixed-size "fingerprint" of the DICOM data. Any change to the data produces a completely different hash.
- Public Key Encryption: The signer encrypts the hash with their private key. Anyone can decrypt it with the public key, but only the private key holder could have created it.
- Certificate Chains: X.509 certificates bind public keys to identities, verified through a chain of trust to a Certificate Authority (CA).
What Gets Signed?
A critical design decision in DICOM signatures is which attributes to include in the signature. The MAC (Message Authentication Code) calculation includes:
- Always Signed: SOP Class/Instance UIDs (prevents substitution attacks), Patient demographics, Pixel Data (the actual image)
- Usually Excluded: File Meta Information (changes during transfer), the Digital Signatures Sequence itself, Group Length elements
- Configurable: Application-specific decisions about other attributes
The choice of what to sign determines what's protected. Signing only pixel data protects against image tampering but not against changing patient demographics attached to the image.
Signature Profiles and Use Cases
DICOM PS3.15 defines signature profiles for specific scenarios:
- Creator RSA: The acquisition modality signs images at creation time, proving they came from that device
- Authorization RSA: A physician signs a report or result, providing legal attestation
- SR RSA: Specific requirements for Structured Reports, covering content sequences
The Timestamp Problem
A subtle issue with digital signatures is proving when the signature was created. Without a trusted timestamp, a signer could claim their signature was created before a certificate was revoked. Trusted timestamping services (RFC 3161) can be incorporated to provide cryptographic proof of signing time.
Why Digital Signatures?
DICOM digital signatures serve three critical purposes:
| Purpose | Description |
|---|---|
| Data Integrity | Detect any modification to signed data |
| Authentication | Verify the identity of the signer |
| Non-repudiation | Signer cannot deny having signed |
Signature Structure in DICOM
DICOM stores signatures in the Digital Signatures Sequence (FFFA,FFFA):
System.out.println("Digital Signatures Sequence (FFFA,FFFA):");
System.out.println(" Each Digital Signature Item contains:");
System.out.println();
System.out.println(" MAC ID Number (0400,0005)");
System.out.println(" Identifies the MAC algorithm");
System.out.println();
System.out.println(" Digital Signature UID (0400,0100)");
System.out.println(" Unique identifier for this signature");
System.out.println();
System.out.println(" Digital Signature DateTime (0400,0105)");
System.out.println(" When the signature was created");
System.out.println();
System.out.println(" Certificate Type (0400,0110)");
System.out.println(" X509_1993_SIG (X.509 certificate)");
System.out.println();
System.out.println(" Certificate of Signer (0400,0115)");
System.out.println(" The X.509 certificate (encoded)");
System.out.println();
System.out.println(" Signature (0400,0120)");
System.out.println(" The actual digital signature bytes");
DICOM Signature Profiles
DICOM defines several signature profiles for different use cases (PS3.15):
| Profile | Use Case |
|---|---|
| Base RSA | Minimum requirements for any DICOM signature |
| Creator RSA | Equipment creating DICOM objects |
| Authorization | Physicians authorizing reports/results |
| SR RSA | Specifically for Structured Reports |
Attributes Commonly Signed
System.out.println("Always signed:");
System.out.println(" - SOP Class UID, SOP Instance UID");
System.out.println(" - Patient Name, Patient ID");
System.out.println(" - Study/Series Instance UIDs");
System.out.println(" - Pixel Data (for images)");
System.out.println(" - Content Sequence (for SR)");
System.out.println("Usually excluded from signing:");
System.out.println(" - File Meta Information");
System.out.println(" - Digital Signatures Sequence itself");
System.out.println(" - Group Length elements");
Verification Process
Verifying a digital signature involves these steps:
System.out.println("1. Extract Signature Information");
System.out.println(" - Read Digital Signatures Sequence");
System.out.println(" - Get certificate and signature bytes");
System.out.println(" - Get list of signed attributes");
System.out.println("2. Validate Certificate");
System.out.println(" - Check certificate chain to trusted CA");
System.out.println(" - Verify certificate is not expired");
System.out.println(" - Check certificate is not revoked (CRL/OCSP)");
System.out.println("3. Calculate MAC");
System.out.println(" - Extract signed attributes");
System.out.println(" - Encode using specified transfer syntax");
System.out.println(" - Calculate hash using specified algorithm");
System.out.println("4. Verify Signature");
System.out.println(" - Use public key from certificate");
System.out.println(" - Decrypt signature to get original hash");
System.out.println(" - Compare with calculated hash");
System.out.println("5. Report Result");
System.out.println(" - VALID: Hashes match, certificate valid");
System.out.println(" - INVALID: Hashes don't match (data modified)");
System.out.println(" - UNKNOWN: Cannot verify certificate chain");
Implementation with PixelMed
System.out.println("Creating Signatures (PixelMed):");
System.out.println(" // Load private key and certificate");
System.out.println(" KeyStore ks = KeyStore.getInstance(\"PKCS12\");");
System.out.println(" ks.load(new FileInputStream(\"key.p12\"), password);");
System.out.println(" PrivateKey privateKey = (PrivateKey) ks.getKey(alias, password);");
System.out.println(" Certificate cert = ks.getCertificate(alias);");
System.out.println();
System.out.println(" // Sign the DICOM object");
System.out.println(" DigitalSignatures.sign(attributeList, privateKey, cert, ...);");
System.out.println("Verifying Signatures (PixelMed):");
System.out.println(" // Read the DICOM file");
System.out.println(" AttributeList list = new AttributeList();");
System.out.println(" list.read(dicomFile);");
System.out.println();
System.out.println(" // Verify signatures");
System.out.println(" DigitalSignatures.verify(list, trustStore);");
MAC Algorithms
Supported MAC (Message Authentication Code) algorithms:
| Algorithm | Status |
|---|---|
| RIPEMD160 | Legacy |
| MD5 | Deprecated (insecure) |
| SHA1 | Deprecated (use SHA-256+) |
| SHA256 | Recommended |
| SHA384 | Strong |
| SHA512 | Strongest |
Certificate Requirements
- X.509 v3 certificate
- Key Usage: Digital Signature
- Minimum key size: 2048-bit RSA or 256-bit ECDSA
- Recommended algorithm: SHA256withRSA
Best Practices
- Use SHA-256 or stronger hash algorithm
- Use 2048+ bit RSA keys
- Include timestamp from trusted authority
- Protect private keys appropriately
- Have a certificate revocation strategy
- Document signature policy and procedures
Conclusion
DICOM digital signatures provide essential security guarantees for medical imaging data. They ensure that diagnostic images and reports can be trusted, supporting both clinical decision-making and legal/regulatory requirements.
Implementing digital signatures requires careful attention to certificate management, algorithm selection, and operational procedures to maintain the security benefits over time. In the next tutorial in this series, I will cover DICOM secure communications using TLS for protecting PHI in transit. See you then!