Main Content

digest

Generate cryptographic hash for package

Since R2024b

    Description

    chksum = digest(pkg) returns a string containing a SHA-256 cryptographic hash for the package. The hash is a unique, fixed-size string based on the package folder contents.

    Use the SHA-256 digests returned by digest to determine if a package has been changed. For additional information, see Security Considerations for Shared Repositories.

    example

    Examples

    collapse all

    Generate a checksum for the package MyPackage.

    pkg = mpmsearch("MyPackage");
    chksum = digest(pkg)
    chksum = 
    
        "751a4bc964745d33f17a6e0f89c0230714d30bef5f7256e398eebbd8fe2bf9a4"

    Use digest to precompute and provide the SHA-256 digests of the packages in the repository alongside the packages or via some other secure distribution channel such as a secure website.

    pkg = mpmlist("MyPackage");
    SHA = digest(pkg)
    SHA = 
    
        "ab0863fa6a1eeb0fade092abd583323bee73d1dd5ce4a74aa031e4995ae2bb79"

    Use mpminstall with the option Verbosity="detailed". mpminstall will recompute and display the current digest value for each package to be installed.

    mpminstall("MyPackage",Verbosity="detailed")
    The following packages will be installed:
        MyPackage@1.0.0  (digest: ab0863fa6a1eeb0fade092abd583323bee73d1dd5ce4a74aa031e4995ae2bb79)
    
    Do you want to continue? [YES/no]:

    If this value does not match the originally computed digest value, the package has been altered, and installation should be cancelled by responding “no” at the “Do you want to continue?” prompt. Users should then report this discrepancy to the shared repository’s administrator.

    Input Arguments

    collapse all

    Package, specified as a matlab.mpm.Package object.

    Version History

    Introduced in R2024b