Overview
The hash utilities module provides classes for generating cryptographic hashes using various SHA algorithms. These are commonly used for digital signatures in UBL documents. Source:src/tools/shas.ts
SHA256
Class for generating SHA-256 cryptographic hashes.Methods
getHash
Generates a SHA-256 hash of the provided content.The string content to hash
Encoding of the input content
Encoding format for the output hash
string - The computed hash in the specified output encoding
getAlgorithmName
Returns the W3C algorithm identifier URI for SHA-256. Returns:string - "http://www.w3.org/2001/04/xmlenc#sha256"
Examples
SHA384
Class for generating SHA-384 cryptographic hashes.Methods
getHash
Generates a SHA-384 hash of the provided content.The string content to hash
Encoding of the input content
Encoding format for the output hash
string - The computed hash in the specified output encoding
getAlgorithmName
Returns the W3C algorithm identifier URI for SHA-384. Returns:string - "http://www.w3.org/2001/04/xmlenc#sha256"
Examples
SHA1
Class for generating SHA-1 cryptographic hashes.SHA-1 is considered cryptographically weak for security-critical applications. Use SHA-256 or stronger algorithms for new implementations.
Methods
getHash
Generates a SHA-1 hash of the provided content.The string content to hash
Encoding of the input content
Encoding format for the output hash
string - The computed hash in the specified output encoding
getAlgorithmName
Returns the W3C algorithm identifier URI for SHA-1. Returns:string - "http://www.w3.org/2000/09/xmldsig#sha1"
Examples
SHA512
Class for generating SHA-512 cryptographic hashes.Methods
getHash
Generates a SHA-512 hash of the provided content.The string content to hash
Encoding of the input content
Encoding format for the output hash
string - The computed hash in the specified output encoding
getAlgorithmName
Returns the W3C algorithm identifier URI for SHA-512. Returns:string - "http://www.w3.org/2001/04/xmlenc#sha512"
Examples
Common Usage Patterns
Use Cases
- Digital signatures for UBL invoices and documents
- Document integrity verification
- Compliance with XML signature standards (XMLDSig)
- Cryptographic operations in e-invoicing systems
- Content verification and tamper detection
Algorithm Recommendations
- SHA-256: Recommended for most UBL document signing scenarios
- SHA-384: For enhanced security requirements
- SHA-512: For maximum security or specific regulatory requirements
- SHA-1: Only for legacy system compatibility (not recommended for new implementations)