Giter Site home page Giter Site logo

klcz / digest-wasm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mllcms/digest-wasm

0.0 0.0 0.0 285 KB

前端哈希库-WASM

Home Page: https://mllcms.github.io/digest-wasm/

License: Apache License 2.0

JavaScript 34.54% Rust 21.91% HTML 42.16% Batchfile 1.39%

digest-wasm's Introduction

DigestWasm

基于 RustCrypto 库编译而成的 wasm 哈希库

用于提高 Md5 Sha256 Sha512 等计算速度

WebAssembly

测试地址

Install

pnpm install digest-wasm

Usage

正常使用

import {Md5, Sha256, Sha512} from "digest-wasm";

const md5 = await Md5.digest("Hello World!")
const sha256 = await Sha256.digest("Hello World!")
const sha512 = await Sha512.digest("Hello World!")
const buffer = await new Blob(["Hello World!"]).arrayBuffer()
const md5 = await Md5.digest_u8(new Uint8Array(buffer))
const sha256 = await Sha256.digest_u8(new Uint8Array(buffer))
const sha512 = await Sha512.digest_u8(new Uint8Array(buffer))

增量计算

import {Md5, Sha256, Sha512} from "digest-wasm";

const file_hash = async (file, chunkSize = 128 << 20) => {
    const hash = Md5.new()
    // const hash = Sha256.new()
    // const hash = Sha512.new()

    for (let i = 0; i < Math.ceil(file.size / chunkSize); i++) {
        const chuck = await file.slice(chunkSize * i, chunkSize * (i + 1)).arrayBuffer()
        await hash.update(new Uint8Array(chuck))
    }

    return hash.finalize()
}

静态引入

下载 dist 目录下的 digest_wasm.js

digest-wasm's People

Contributors

mllcms avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.