WebCryptoService
Provides cryptographic operations using the Web Crypto API (SubtleCrypto). Supports hashing, AES-GCM encryption/decryption, key generation, key import/export, and secure random generation.
TypeScriptexample.ts
import { WebCryptoService } from '@angular-helpers/security'# Methods
| Method | Signature | Returns | Description |
|---|---|---|---|
isSupported | isSupported(): boolean | boolean | Public method isSupported. |
hash | hash(data: string | ArrayBuffer, algorithm: HashAlgorithm): Promise<string> | Promise<string> | Public method hash. |
generateAesKey | generateAesKey(length: AesKeyLength): Promise<CryptoKey> | Promise<CryptoKey> | Public method generateAesKey. |
encryptAes | encryptAes(key: CryptoKey, data: string | ArrayBuffer): Promise<AesEncryptResult> | Promise<AesEncryptResult> | Public method encryptAes. |
decryptAes | decryptAes(key: CryptoKey, ciphertext: ArrayBuffer, iv: Uint8Array<ArrayBuffer>): Promise<string> | Promise<string> | Public method decryptAes. |
exportKey | exportKey(key: CryptoKey): Promise<JsonWebKey> | Promise<JsonWebKey> | Public method exportKey. |
importAesKey | importAesKey(jwk: JsonWebKey): Promise<CryptoKey> | Promise<CryptoKey> | Public method importAesKey. |
generateRandomBytes | generateRandomBytes(length: number): Uint8Array | Uint8Array | Public method generateRandomBytes. |
randomUUID | randomUUID(): string | string | Public method randomUUID. |
generateHmacKey | generateHmacKey(algorithm: HmacAlgorithm): Promise<CryptoKey> | Promise<CryptoKey> | Public method generateHmacKey. |
sign | sign(key: CryptoKey, data: string | ArrayBuffer): Promise<string> | Promise<string> | Signs data with an HMAC key. Returns a hex-encoded signature. |
verify | verify(key: CryptoKey, data: string | ArrayBuffer, signature: string): Promise<boolean> | Promise<boolean> | Verifies an HMAC signature (hex-encoded). Returns false for malformed input — never throws. |
importHmacKey | importHmacKey(jwk: JsonWebKey, algorithm: HmacAlgorithm): Promise<CryptoKey> | Promise<CryptoKey> | Public method importHmacKey. |