2 Star 0 Fork 0

haugnxy / JavaScript-MD5

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

JavaScript MD5

Demo

JavaScript MD5 Demo

Description

JavaScript MD5 implementation. Compatible with server-side environments like Node.js, module loaders like RequireJS, Browserify or webpack and all web browsers.

Usage

Client-side

Include the (minified) JavaScript MD5 script in your HTML markup:

<script src="js/md5.min.js"></script>

In your application code, calculate the (hex-encoded) MD5 hash of a string by calling the md5 method with the string as argument:

var hash = md5("value"); // "2063c1608d6e0baf80249c42e2be5804"

Server-side

The following is an example how to use the JavaScript MD5 module on the server-side with Node.js.

Create a new directory and add the md5.js file. Or alternatively, install the blueimp-md5 package with npm:

npm install blueimp-md5

Add a file server.js with the following content:

require("http").createServer(function (req, res) {
    // The md5 module exports the md5() function:
    var md5 = require("./md5"),
    // Use the following version if you installed the package with npm:
    // var md5 = require("blueimp-md5"),
        url  = require("url"),
        query = url.parse(req.url).query;
    res.writeHead(200, {"Content-Type": "text/plain"});
    // Calculate and print the MD5 hash of the url query:
    res.end(md5(query));
}).listen(8080, "localhost");
console.log("Server running at http://localhost:8080/");

Run the application with the following command:

node server.js

Requirements

The JavaScript MD5 script has zero dependencies.

API

Calculate the (hex-encoded) MD5 hash of a given string value:

var hash = md5("value"); // "2063c1608d6e0baf80249c42e2be5804"

Calculate the (hex-encoded) HMAC-MD5 hash of a given string value and key:

var hash = md5("value", "key"); // "01433efd5f16327ea4b31144572c67f6"

Calculate the raw MD5 hash of a given string value:

var hash = md5("value", null, true);

Calculate the raw HMAC-MD5 hash of a given string value and key:

var hash = md5("value", "key", true);

Tests

The JavaScript MD5 project comes with Unit Tests.
There are two different ways to run the tests:

  • Open test/index.html in your browser or
  • run npm test in the Terminal in the root path of the repository package.

The first one tests the browser integration, the second one the node.js integration.

License

The JavaScript MD5 script is released under the MIT license.

MIT License Copyright © 2011 Sebastian Tschan, https://blueimp.net Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/huangxy3/JavaScript-MD5.git
git@gitee.com:huangxy3/JavaScript-MD5.git
huangxy3
JavaScript-MD5
JavaScript-MD5
master

搜索帮助