Crypto
The TypeScript Crypto API mirrors the public methods and algorithm casing of .NET CryptoUtil. AES-GCM payloads, password-based AES payloads, PBKDF2 password hashes, and PEM keys interoperate across both implementations.
import { AESDecryptWithPassword, AESEncryptWithPassword } from "@fast-china/utils";
const payload = await AESEncryptWithPassword("protected content", "correct horse battery staple");
const plaintext = await AESDecryptWithPassword(payload, "correct horse battery staple");
plaintext;
const jsonPayload = await AESEncryptWithPassword('{"id":1}', "correct horse battery staple");
const result = (await AESDecryptWithPassword(jsonPayload, "correct horse battery staple")).parseJson<{ id: number }>();Base64 and Crypto text decoding/decryption functions return the primitive-string DecodedText type, which can be used directly as a string; an explicit .parseJson<T = any>() call attempts JSON parsing and returns the original string when parsing fails. The first text decode lazily installs a non-enumerable String.prototype.parseJson; a foreign method with the same name causes an explicit conflict error. The generic type does not validate untrusted JSON or guarantee an object result at runtime.
Store passwords with HashPasswordPBKDF2SHA256 and VerifyPasswordPBKDF2SHA256. MD5, SHA-1, AES-CBC, and AES-ECB do not provide password-storage or authenticated-encryption guarantees. See the API reference for the complete method list and security boundaries.
CryptoJS is bundled into the ESM and CDN artifacts for the compatibility hash and AES APIs. Consumers do not install or resolve crypto-js subpaths; applications that do not use Crypto APIs can still remove the independent crypto module through Tree Shaking.
