Skip to content

Commit c0ace2f

Browse files
committed
Initial commit.
0 parents  commit c0ace2f

File tree

8 files changed

+706
-0
lines changed

8 files changed

+706
-0
lines changed

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# JavaScript MD5
2+
3+
## Demo
4+
[JavaScript MD5 Demo](http://blueimp.github.com/JavaScript-MD5/)
5+
6+
## Usage
7+
8+
### Client-side
9+
Include the (minified) JavaScript [MD5](http://en.wikipedia.org/wiki/MD5) script in your HTML markup:
10+
11+
```html
12+
<script src="md5.min.js"></script>
13+
```
14+
15+
In your application code, calculate the ([hex](http://en.wikipedia.org/wiki/Hexadecimal)-encoded) [MD5](http://en.wikipedia.org/wiki/MD5) hash of a string by calling the **md5** method with the string as argument:
16+
17+
```js
18+
var hash = md5("value"); // "2063c1608d6e0baf80249c42e2be5804"
19+
```
20+
21+
### Server-side
22+
23+
The following is an example how to use the JavaScript MD5 module on the server-side with [node.js](http://nodejs.org/).
24+
25+
Create a new directory and add the **md5.js** file. Or alternatively, install the **blueimp-md5** package with [npm](http://npmjs.org/):
26+
27+
```sh
28+
npm install blueimp-md5
29+
```
30+
31+
Add a file **server.js** with the following content:
32+
33+
```js
34+
require("http").createServer(function (req, res) {
35+
// The md5 module exports the md5() function:
36+
var md5 = require("./md5").md5,
37+
// Use the following version if you installed the package with npm:
38+
// var md5 = require("blueimp-md5").md5,
39+
url = require("url"),
40+
query = url.parse(req.url).query;
41+
res.writeHead(200, {"Content-Type": "text/plain"});
42+
// Calculate and print the MD5 hash of the url query:
43+
res.end(md5(query));
44+
}).listen(8080, "localhost");
45+
console.log("Server running at http://localhost:8080/");
46+
```
47+
48+
Run the application with the following command:
49+
50+
```sh
51+
node server.js
52+
```
53+
54+
## Requirements
55+
The JavaScript MD5 script has zero dependencies.
56+
57+
## API
58+
59+
Calculate the ([hex](http://en.wikipedia.org/wiki/Hexadecimal)-encoded) [MD5](http://en.wikipedia.org/wiki/MD5) hash of a given string value:
60+
61+
```js
62+
var hash = md5("value"); // "2063c1608d6e0baf80249c42e2be5804"
63+
```
64+
65+
Calculate the ([hex](http://en.wikipedia.org/wiki/Hexadecimal)-encoded) [HMAC](http://en.wikipedia.org/wiki/HMAC)-MD5 hash of a given string value and key:
66+
67+
```js
68+
var hash = md5("value", "key"); // "01433efd5f16327ea4b31144572c67f6"
69+
```
70+
71+
Calculate the raw [MD5](http://en.wikipedia.org/wiki/MD5) hash of a given string value:
72+
73+
```js
74+
var hash = md5("value", null, true);
75+
```
76+
77+
Calculate the raw [HMAC](http://en.wikipedia.org/wiki/HMAC)-MD5 hash of a given string value and key:
78+
79+
```js
80+
var hash = md5("value", "key", true);
81+
```
82+
83+
## License
84+
The JavaScript MD5 script is released under the [MIT license](http://creativecommons.org/licenses/MIT/).

index.html

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<!DOCTYPE HTML>
2+
<!--
3+
/*
4+
* JavaScript MD5 Demo 1.0
5+
* https://github.com/blueimp/JavaScript-MD5
6+
*
7+
* Copyright 2011, Sebastian Tschan
8+
* https://blueimp.net
9+
*
10+
* Licensed under the MIT license:
11+
* http://creativecommons.org/licenses/MIT/
12+
*/
13+
-->
14+
<html lang="en">
15+
<head>
16+
<meta charset="utf-8">
17+
<title>JavaScript MD5 Demo</title>
18+
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css">
19+
<style type="text/css">
20+
.page-header {
21+
background-color: #f5f5f5;
22+
padding: 80px 20px 10px;
23+
margin: 0 -20px 20px;
24+
border: 1px solid #DDD;
25+
-webkit-border-radius: 0 0 6px 6px;
26+
-moz-border-radius: 0 0 6px 6px;
27+
border-radius: 0 0 6px 6px;
28+
}
29+
</style>
30+
<!--[if lt IE 7]>
31+
<style type="text/css">
32+
.span10, .span6 {
33+
display: inline;
34+
float: left;
35+
margin-left: 20px;
36+
}
37+
.topbar {
38+
position: absolute;
39+
}
40+
.topbar ul, .topbar .container {
41+
padding-top: 10px;
42+
}
43+
.topbar li {
44+
display: inline;
45+
margin-right: 10px;
46+
}
47+
.topbar a:hover {
48+
color: #fff;
49+
}
50+
</style>
51+
<![endif]-->
52+
<meta name="description" content="JavaScript MD5 implementation.">
53+
</head>
54+
<body>
55+
<div class="topbar">
56+
<div class="fill">
57+
<div class="container">
58+
<a class="brand" href="https://github.com/blueimp/JavaScript-MD5">JavaScript MD5</a>
59+
<ul class="nav">
60+
<li class="active"><a href="#">Demo</a></li>
61+
<li><a href="https://github.com/blueimp/JavaScript-MD5/downloads">Downloads</a></li>
62+
<li><a href="https://github.com/blueimp/JavaScript-MD5">Source Code</a></li>
63+
<li><a href="https://github.com/blueimp/JavaScript-MD5">Documentation</a></li>
64+
<li><a href="https://github.com/blueimp/JavaScript-MD5/issues">Issues</a></li>
65+
<li><a href="test/">Test</a></li>
66+
<li><a href="https://blueimp.net">&copy; Sebastian Tschan</a></li>
67+
</ul>
68+
</div>
69+
</div>
70+
</div>
71+
<div class="container">
72+
<div class="page-header">
73+
<h1>JavaScript MD5 Demo</h1>
74+
<p>JavaScript <a href="http://en.wikipedia.org/wiki/MD5">MD5</a> implementation.<br>
75+
Compatible with server-side environments like <a href="http://nodejs.org/">node.js</a>, module loaders like <a href="http://requirejs.org/">RequireJS</a> and all web browsers.</p>
76+
</div>
77+
<div class="row">
78+
<div class="span10">
79+
<h2>Input</h2>
80+
<textarea class="xxlarge" rows="6" id="input"></textarea>
81+
</div>
82+
<div class="span6">
83+
<h2>Result</h2>
84+
<div class="well" id="result"></div>
85+
<p>
86+
<button class="btn primary" id="calculate">Calculate</button>
87+
<button class="btn" type="reset" id="reset">Reset</button>
88+
</p>
89+
</div>
90+
</div>
91+
</div>
92+
<script src="md5.min.js"></script>
93+
<!-- jQuery is not required, but included for the demo -->
94+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
95+
<script>
96+
/*global jQuery, md5 */
97+
(function ($) {
98+
'use strict';
99+
var calculate = function () {
100+
$('#result').html(md5($('#input').val()));
101+
},
102+
init = function () {
103+
$('#input').val('日本');
104+
$('#result').empty();
105+
};
106+
init();
107+
$('#calculate').on('click', calculate);
108+
$('#reset').on('click', init);
109+
}(jQuery));
110+
</script>
111+
</body>
112+
</html>

0 commit comments

Comments
 (0)