• Intro Headers Instructions Macros Commands
Fork me on GitHub
    • Getting Started
      • Introduction
      • How to install bnd
      • Guided Tour Workspace & Projects
      • bnd / bndlib Features and JAR Wrapping Techniques
      • FAQ - Frequently Asked Questions
    • Concepts and Practices
      • Concepts
      • Background
      • Best practices
    • Build and Development
      • Build
      • Generating JARs
      • Versioning
      • Baselining
      • Service Components
      • Metatype
      • Contracts
      • Bundle Annotations
      • Accessor Properties
      • SPI Annotations
    • Dependency and Launching
      • Resolving Dependencies
      • Launching
      • Startlevels
    • Testing
      • Testing
      • Testing with Launchpad
    • Packaging and Distribution
      • Packaging Applications
      • JPMS Libraries
      • Wrapping Libraries to OSGi Bundles
    • Documentation and Tools
      • Generating Documentation
      • bnd CLI Commands
      • For Developers
      • Templates for Workspaces
      • Tips for Windows users
      • Tools bound to bnd
    • Reference Material
      • Reference
      • Headers
      • Instruction Reference
      • Instruction Index
      • Macro Reference
      • Macro Index
      • Plugins
      • External Plugins
    • Configuration and Troubleshooting
      • Settings
      • Errors
      • Warnings
  • sha1 ';' RESOURCE

    Prev Next
    Analyzer
    Calculate SHA-1 digest of a resource in the bundle

    Summary

    The sha1 macro calculates the SHA-1 hash of a resource that exists within the current bundle JAR. The result can be returned as either Base64 (default) or hexadecimal encoding.

    Syntax

    ${sha1;<resource-path>[;<encoding>]}
    

    Parameters

    • resource-path - Path to a resource within the bundle (e.g., “META-INF/MANIFEST.MF”)
    • encoding (optional) - Output encoding: “hex” for hexadecimal, “base64” for Base64 (default)

    Behavior

    • Locates the resource within the bundle being built
    • Calculates the SHA-1 digest of the resource contents
    • Returns the digest in the specified encoding (Base64 by default)
    • Throws an exception if the resource is not found

    Examples

    Get SHA-1 of a resource (Base64):

    ${sha1;META-INF/services/com.example.Service}
    # Returns Base64-encoded SHA-1
    

    Get SHA-1 in hexadecimal format:

    ${sha1;config/application.properties;hex}
    # Returns: "356a192b7913b04c54574d18c28d46e6395428ab" (example)
    

    Hash manifest file:

    manifest.sha1=${sha1;META-INF/MANIFEST.MF;hex}
    

    Verify resource integrity:

    Bundle-ResourceSHA1: ${sha1;important-config.xml}
    

    Use Cases

    • Verifying resource integrity in bundles
    • Generating resource checksums for validation
    • Creating content-based identifiers
    • Implementing resource version checking
    • Integrity verification in manifests
    • Detecting resource tampering

    Notes

    • Resource path is relative to the bundle root
    • Only works with resources that are part of the bundle being built
    • SHA-1 is stronger than MD5 but still not recommended for security-critical applications
    • Default encoding is Base64
    • Hex encoding produces lowercase hexadecimal strings
    • Throws FileNotFoundException if resource doesn’t exist
    • See also: ${md5} and ${digest} for other hash algorithms

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home