@li0ard/sm4 - v0.1.0
    Preparing search index...

    @li0ard/sm4 - v0.1.0

    @li0ard/sm4
    SM4 (GB/T 32907-2016) cipher implementation in pure TypeScript
    docs




    # from NPM
    npm i @li0ard/sm4

    # from JSR
    bunx jsr i @li0ard/sm4
    • [x] Electronic Codebook (ECB)
    • [x] Cipher Block Chaining (CBC)
    • [x] Output Feedback (OFB)
    • [x] Counter (CTR)
    • [x] Cipher Feedback (CFB)
    • [x] Galois/Counter Mode (GCM)
    • Provides simple and modern API
    • Most of the APIs are strictly typed
    • Fully complies with GB/T 32907-2016 standard
    • Supports Bun, Node.js, Deno, Browsers
    import { encryptECB, decryptECB } from "@li0ard/sm4";

    const key = hexToBytes("0123456789ABCDEFFEDCBA9876543210");
    const plaintext = hexToBytes("AAAA....AA");
    const ciphertext = encryptECB(key, plaintext);

    console.log(ciphertext);
    console.log(decryptECB(key, ciphertext));
    import { encryptCBC, decryptCBC } from "@li0ard/sm4";

    const key = hexToBytes("0123456789ABCDEFFEDCBA9876543210");
    const key = hexToBytes("000102030405060708090A0B0C0D0E0F");
    const plaintext = hexToBytes("AAAA....AA");
    const ciphertext = encryptCBC(key, plaintext, iv);

    console.log(ciphertext);
    console.log(decryptCBC(key, ciphertext, iv));