How to use the SHA1 function from crypto-js

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

282
283
284
285
286
287
288
289
290
291
// 引用 crypto-js 加密模块
var CryptoJS = require('crypto-js')

function SHA1Encrypt() {
    var text = "I love python!"
    return CryptoJS.SHA1(text).toString();
}

console.log(SHA1Encrypt())  // 23c02b203bd2e2ca19da911f1d270a06d86719fb
```
fork icon34
star icon57
watch icon0

+ 7 other calls in file

139
140
141
142
143
144
145
146
147
148
  }
}

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

function sha256(ba) {
fork icon21
star icon30
watch icon9

+ 3 other calls in file

104
105
106
107
108
109
110
111
112
113
// 引用 crypto-js 加密模块
var CryptoJS = require('crypto-js')

function SHA1Test(text) {
    // 传入text参数,对其进行sha1加密,SHA1也可替换为SHA224, SHA256等其它种类的算法,这里仅举SHA1为例。
    return CryptoJS.SHA1(text).toString()
}

console.log(SHA1Test('DrSHW'))  // e2df7ce713e52cc1868e87663dbd68b6881306e4
```
fork icon2
star icon4
watch icon2

+ 7 other calls in file

113
114
115
116
117
118
119
120
121
122
MD5: function(data, secret) {
  return CryptoJS.MD5(secret + data);
},

SHA1: function(data, secret) {
  return CryptoJS.SHA1(secret + data);
},

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

+ 9 other calls in file

61
62
63
64
65
66
67
68
69
70
 * @param  {Object}  params   The object to encode
 * @return {String}           The request signature
 */
ZB.prototype.signMessage = function getMessageSignature(params) {
    var presign_params = formatParameters(params);
    var secret_key = CryptoJS.SHA1(this.secret_key);
    return _.toString(CryptoJS.HmacMD5(presign_params, _.toString(secret_key)));
};

/**
fork icon2
star icon4
watch icon1

9
10
11
12
13
14
15
16
17
18
case "MD5":
    this.hashAlgorithm = CryptoJS.MD5
    break;
case "SHA-1":
case "SHA1":
    this.hashAlgorithm = CryptoJS.SHA1
    break;
case "SHA-256":
case "SHA256":
    this.hashAlgorithm = CryptoJS.SHA256
fork icon2
star icon3
watch icon0

68
69
70
71
72
73
74
75
76
77
export function md5(string){
  return CryptoJS.MD5(string).toString()
}

export function sha1(string){
  return CryptoJS.SHA1(string).toString()
}

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

+ 2 other calls in file

56
57
58
59
60
61
62
63
64
65
serect: '',
md5() {
  return CryptoJS.MD5(this.text).toString();
},
sha1() {
  return CryptoJS.SHA1(this.text).toString();
},
sha224() {
  return CryptoJS.SHA224(this.text).toString();
},
fork icon0
star icon1
watch icon1

+ 17 other calls in file

20
21
22
23
24
25
26
27
28
29
function md5(s) {
    return CryptoJS.MD5(s).toString()
}

function sha1(s) {
    return CryptoJS.SHA1(s).toString();
}

function sha224(s) {
    return CryptoJS.SHA224(s).toString();
fork icon0
star icon0
watch icon1