npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crypto.web.js

v1.0.5

Published

crypto.js浏览器版本,提供常用的加密封装

Downloads

9

Readme

crypto.js浏览器版本,提供常用的加密封装

English Readme

感谢以下2个优秀的开源库:

  1. spark-md5, 这个经本人测试, 确实是纯js版中性能最高的一个, 本仓库引入进来, 调整为ESM方式使用。
  2. base64, 完整的base64库, 相比原生的 btoa()方法, 这个支持对中文进行编码。

以上这2个库, 在index.js中有引入。对体积有要求的, 可以单独使用。

// 多合一
import { sha1, hmac, md5, base64encode } from '//jscdn.ink/crypto.web.js/latest/index.js'  // 大陆用户可使用此加速地址

import { md5, md5Sum } from '//jscdn.ink/crypto.web.js/latest/md5.js'

import { base64encode, base64decode } from '//jscdn.ink/crypto.web.js/latest/base64.js'

APIs

1. md5(str<String>|<Number>)

常规的md5函数, 可对字符串(数字类型也可以), 进行加密。如果要对一个超级大的文本进行md5求值的话, 建议改成下面的 md5Sum()

2. md5Sum(ab<ArrayBuffer>)

该方法可用于对文件求md5值, 需传入ArrayBuffer对象, 可用 FileReader得到arraybuffer值, 新浏览器的Blob对象,也有个arraybuffer原型方法。

3. base64encode(str<String>)

base64编码, 支持中文。

4. base64decode(str<String>)

base64解码。

5. uuid()

生成一个唯一的24位的随机字符串。 只保证单机唯一。

6. ab2hex(ab<ArrayBuffer>)

将一个arraybuffer对象, 转为 十六进制字符串。

7. ab2bin(ab<ArrayBuffer>)

将一个arraybuffer对象, 转为 Binary字符串。

8. sha1(str<String>)

对指定字符串求 sha1值。

注意: 该方法返回的不是字符串, 而是一个Promise对象。

9. sha256(str<String>)

对指定字符串求 sha256值。

注意: 该方法返回的不是字符串, 而是一个Promise对象。

10. sha512(str<String>)

对指定字符串求 sha512值。

注意: 该方法返回的不是字符串, 而是一个Promise对象。

11. hash(algorithm<String>, data<String>|<ArrayBuffer>|<Uint8Array>)

散列算法(也称为哈希算法),用来实现一些重要数据的模糊处理,以达到隐藏明文的目的。 上面的sha1、sha256等,其实就是基于这个再次封装的结果; algorithm,可选值有: SHA-1, SHA-256, SHA-384, SHA-512。

注意: 该方法返回的不是字符串, 而是一个Promise对象。

12. hmac(algorithm<String>, data<String>|<ArrayBuffer>|<Uint8Array>, key<String>|<Uint8Array>, outEncode<String>)

HMAC算法,是在散列算法的基础上,与一个密钥结合在一起,以阻止对签名完整性的破坏。 与上面的散列算法相比,多了一个密钥的参数key。

注意: 该方法返回的不是字符串, 而是一个Promise对象。