How to use the MD5 function from crypto-js

Find comprehensive JavaScript crypto-js.MD5 code examples handpicked from public code repositorys.

crypto-js.MD5 is a method that generates an MD5 hash of a given string or data.

194
195
196
197
198
199
200
201
202
203
// 引用 crypto-js 加密模块
var CryptoJS = require('crypto-js')

function MD5Test() {
    var text = "I love python!"
    return CryptoJS.MD5(text).toString()
}

console.log(MD5Test())  // 21169ee3acd4a24e1fcb4322cfd9a2b8
```
fork icon34
star icon57
watch icon0

+ 7 other calls in file

151
152
153
154
155
156
157
158
159
160
  return wa2ba(hash.words)
}

function md5(ba) {
  const ba_obj = CryptoJS.enc.Hex.parse(ba2hex(ba))
  const hash = CryptoJS.MD5(ba_obj)
  return wa2ba(hash.words)
}

//input bytearrays must be of equal length
fork icon21
star icon30
watch icon9

+ 3 other calls in file

How does crypto-js.MD5 work?

crypto-js.MD5 is a function that takes a message (string or WordArray) as input, performs a series of bitwise operations on it, and outputs a 128-bit (32 hexadecimal characters) hash value using the MD5 algorithm, which is commonly used for password hashing and digital signature applications. The resulting hash is deterministic, meaning that the same input message will always result in the same output hash. The hash value is considered to be a one-way function, as it is practically impossible to derive the original message from the hash value.

58
59
60
61
62
63
64
65
66
67
function QD(data) {
    let str1 = data.split("&")
        .sort(function(a, b) {
            return a.localeCompare(b);
        }).join("&").toLowerCase()
    sign = cryptojs.MD5(str1).toString()
    let str = `Rv1rPTnczce|${Math.floor(Date.now() )}|${UserId}|${deviceUid}|1|${version}|0|${sign}|f189adc92b816b3e9da29ea304d4a7e4`
    qdsign = encrypt(str)
    return qdsign
}
fork icon10
star icon15
watch icon2

47
48
49
50
51
52
53
54
55
56
* @param {String} key
* @param {String} encrypted_text (should be a base64 encoded string)
*/ 
_3DES.decrypt = function (key, encrypted_text){

        key            = CryptoJS.MD5(utf8.encode(key)).toString(CryptoJS.enc.Latin1);
        key            = key + key.substring(0, 8); 
        var decipher   = forge.cipher.createDecipher('3DES-ECB', forge.util.createBuffer(key));
        encrypted_text = forge.util.decode64(encrypted_text);
        decipher.start({iv:''});
fork icon3
star icon4
watch icon1

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
const CryptoJS = require("crypto-js");

const message = "Hello, world!";
const hash = CryptoJS.MD5(message);

console.log(hash.toString(CryptoJS.enc.Hex));

In this example, we first import the crypto-js library using require(). We then define a message to hash, and compute the MD5 hash of the message using the CryptoJS.MD5() function. Finally, we log the resulting hash to the console, converting it to a hexadecimal string using the toString() method and the CryptoJS.enc.Hex encoding.

109
110
111
112
113
114
115
116
117
118
 * Available hashing algorithms
 * @namespace
 */
Telepathy.algorithms = {
  MD5: function(data, secret) {
    return CryptoJS.MD5(secret + data);
  },

  SHA1: function(data, secret) {
    return CryptoJS.SHA1(secret + data);
fork icon0
star icon6
watch icon3

+ 9 other calls in file

5
6
7
8
9
10
11
12
13
14
 */
class HashAlgorithmFactory {
    static getHashAlgorithm(hash_type) {
        switch (hash_type) {
            case "MD5":
                this.hashAlgorithm = CryptoJS.MD5
                break;
            case "SHA-1":
            case "SHA1":
                this.hashAlgorithm = CryptoJS.SHA1
fork icon2
star icon3
watch icon0

64
65
66
67
68
69
70
71
72
73
export async function randomBytesHexString(len: number){
  return random(len)
}

export function md5(string){
  return CryptoJS.MD5(string).toString()
}

export function sha1(string){
  return CryptoJS.SHA1(string).toString()
fork icon0
star icon2
watch icon1

+ 2 other calls in file

53
54
55
56
57
58
59
60
61
62

var hash = {
  text: '',
  serect: '',
  md5() {
    return CryptoJS.MD5(this.text).toString();
  },
  sha1() {
    return CryptoJS.SHA1(this.text).toString();
  },
fork icon0
star icon1
watch icon1

+ 17 other calls in file

138
139
140
141
142
143
144
145
146
147
}
urlparse(url) {
    return urls.parse(url, true, true)
}
md5(encryptString) {
    return CryptoJS.MD5(encryptString).toString()
}
haskey(data, key, value) {
    value = typeof value !== 'undefined' ? value : '';
    var spl = key.split('.');
fork icon1
star icon0
watch icon1

+ 4 other calls in file

1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
    }
}


function generateMarvelAPIAuth() {
    let ts = new Date().getTime();
    return "&ts=" + ts + "&hash=" + CryptoJS.MD5(ts + MarvelPrivateKey + MarvelPublicKey).toString() + "&apikey=" + MarvelPublicKey;
}


async function API_MARVEL_GET(name = "") {
    console.log("API_MARVEL_GET: " + name);
fork icon0
star icon9
watch icon3

+ 4 other calls in file

40
41
42
43
44
45
46
47
48
49
is_new = '0';
time = Date.parse(new Date()) / 1000;
type = `10`;
key = 'Zduf4kHl2o@7*LUn';
sign = `id=${id}&is_new=${is_new}&session_id=${session_id}&time=${time}&type=${type}&key=${key}`
sign = MD5(sign).toString().toUpperCase();

return new Promise((resolve, reject) => {
    const url = "http://pic.anngudao.com/tuili/api/clickLog";
    const headers = {
fork icon0
star icon1
watch icon1

+ 14 other calls in file

204
205
206
207
208
209
210
211
212
213
}

const copy = JSON.parse(JSON.stringify(student));
copy.collegeId = undefined;
const serialised = JSON.stringify(copy);
const encrypted = crypto.MD5(serialised).toString(crypto.enc.Hex);
const existingRaw = db.students.get(encrypted);
if (existingRaw !== undefined) {
    const existing = JSON.parse(JSON.stringify(existingRaw));
    db.students.delete(existing.id);
fork icon0
star icon0
watch icon1

+ 29 other calls in file

46
47
48
49
50
51
52
53
54
55
56
      , u = z(t)
      , c = G(e)
      , s = [o, u, i, V(c) && c, a].filter(Boolean).join("+");
        function MD5Test() {


        return CryptoJS.MD5(s).toString()
}
    return {
        source: s,
        signature: (MD5Test(s))
fork icon0
star icon0
watch icon1

+ 4 other calls in file

11
12
13
14
15
16
17
18
19
20
21
22
  for (var i = 0; i < keyLength; i++) {
    var rnum = Math.floor(Math.random() * chars.length);
    randomstring += chars.substring(rnum, rnum + 1);
  }


  return CryptoJS.MD5(randomstring).toString();
};


let encryptMessage = function (data, attachments, publicKey) {
  let key = generateKey(50);
fork icon0
star icon0
watch icon1

+ 4 other calls in file

19
20
21
22
23
24
25
26
27
28
29
let id = {
    firma: 'firma',
    sucursal: 'sucursal',
    department: 'depto',
    name: 'webserverRest',
    id: CryptoJS.MD5(getRandomInt(10000).toString()),
    wildcard: 'wilcard'
};


const opts = {
fork icon0
star icon0
watch icon1

+ 4 other calls in file