How to use the SHA3 function from crypto-js

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

136
137
138
139
140
141
142
143
144
145
},
SHA3_512: function(data, secret) {
  return CryptoJS.SHA3(secret + data, { outputLength: 512 });
},
SHA3_384: function(data, secret) {
  return CryptoJS.SHA3(secret + data, { outputLength: 384 });
},
SHA3_256: function(data, secret) {
  return CryptoJS.SHA3(secret + data, { outputLength: 256 });
},
fork icon0
star icon6
watch icon3

+ 39 other calls in file

22
23
24
25
26
27
28
29
30
31
    this.hashAlgorithm = CryptoJS.SHA512
    break;
case "SHA-3":
case "SHA3":
    const SHA3 = (value, outputLength = 512) => {
        return CryptoJS.SHA3(value, {outputLength: outputLength})
    }
    this.hashAlgorithm = SHA3
    break;
case "RIPEMD-160":
fork icon2
star icon3
watch icon0

71
72
73
74
75
76
77
78
79
80
},
sha512() {
  return CryptoJS.SHA512(this.text).toString();
},
sha3() {
  return CryptoJS.SHA3(this.text).toString();
},
ripemd160() {
  return CryptoJS.RIPEMD160(this.text).toString();
},
fork icon0
star icon1
watch icon1

+ 17 other calls in file

18
19
20
21
22
23
24
25
26
27

function upgradeVersion1(oldKS, password, callback) {
  const { salt, keyHash, encSeed, hdIndex } = oldKS;
  const derivedKey = legacyGenerateEncKey(password, salt);

  const hash = CryptoJS.SHA3(derivedKey).toString();

  if (keyHash !== hash) {
    callback(new Error('Keystore Upgrade: Invalid Password!'));
    return;
fork icon486
star icon0
watch icon77

64
65
66
67
68
69
70
71
72
73
if (!password) { throw new Error('Missing argument !'); }
if (!count || count <= 0) { throw new Error('Please provide a count number above 0'); }
// Processing
let data = password;
for (let i = 0; i < count; ++i) {
    data = CryptoJS.SHA3(data, {
        outputLength: 256,
    });
}
// Result
fork icon61
star icon0
watch icon2

0
1
2
3
4
5
6
7
8
const CryptoJS = require('crypto-js');

export class CryptoUtils {

    public static keccak256(message: string): string {
        const array: any = CryptoJS.SHA3(message, {outputLength: 256});

        return array.toString(CryptoJS.enc.Hex);
    }
fork icon11
star icon0
watch icon2

0
1
2
3
4
5
6
7
8
const CryptoJS = require('crypto-js');

export class CryptoUtils {

    public static keccak256(message: string): string {
        const array = CryptoJS.SHA3(message, {outputLength: 256});

        return array.toString(CryptoJS.enc.Hex);
    }
fork icon11
star icon0
watch icon2

40
41
42
43
44
45
46
47
48
function sha512(s) {
    return CryptoJS.SHA512(s).toString();
}

function sha3(s, c) {
    return CryptoJS.SHA3(s, {
        outputLength: c || 512
    }).toString();
}
fork icon0
star icon0
watch icon1

6
7
8
9
10
11
12
13
14
15
class DHTUtils {
  constructor() {
    console.log('DHTUtils::constructor');
  }
  calcAddress(content) {
    const contentsSha = CryptoJS.SHA3(content).toString(CryptoJS.enc.Hex);
    const contentRipemd = CryptoJS.RIPEMD160(contentsSha).toString(CryptoJS.enc.Hex);
    //console.log('DHTUtils::calcAddress:: contentRipemd=<',contentRipemd,'>');
    const contentBuffer = Buffer.from(contentRipemd,'hex');
    return base32.encode(contentBuffer,bs32Option);
fork icon0
star icon0
watch icon2