How to use the crypto-js.SHA1 function in crypto-js

To help you get started, we’ve selected a few crypto-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kubeflow / pipelines / frontend / server / k8s-helper.ts View on Github external
function getNameOfViewerResource(logdir: string): string {
  // TODO: find some hash function with shorter resulting message.
  return 'viewer-' + crypto.SHA1(logdir);
}
github OriginProtocol / origin / packages / messaging-client / src / Messaging.js View on Github external
}
    const message = Object.assign({}, messageObj)
    // set timestamp
    message.created = Date.now()

    if (!validateMessage(message)) {
      debug('ERR: invalid message')
      return
    }

    for (const key of convObj.keys) {
      try {
        const iv = CryptoJS.lib.WordArray.random(16)
        const messageStr = JSON.stringify(message)
        const shaSub = CryptoJS.enc.Base64.stringify(
          CryptoJS.SHA1(messageStr)
        ).substr(0, 6)
        const encmsg = CryptoJS.AES.encrypt(messageStr + shaSub, key, {
          iv: iv
        }).toString()
        const ivStr = CryptoJS.enc.Base64.stringify(iv)

        return {
          type: 'msg',
          emsg: encmsg,
          i: ivStr,
          address: this.account_key
        }
      } catch (err) {
        debug('Encryption failed', err)
        // Continue to try and encrypt with other keys
      }
github OriginProtocol / origin / packages / messaging-client / src / Messaging.js View on Github external
const buffer = CryptoJS.AES.decrypt(msg, key, {
      iv: CryptoJS.enc.Base64.parse(ivStr)
    })
    let outText
    try {
      outText = buffer.toString(CryptoJS.enc.Utf8)
    } catch (error) {
      return
    }

    if (outText && outText.length > 6) {
      const verifyText = outText.slice(0, -6)
      const shaCheck = outText.substr(-6)
      if (
        shaCheck ==
        CryptoJS.enc.Base64.stringify(CryptoJS.SHA1(verifyText)).substr(0, 6)
      ) {
        return verifyText
      }
    }
  }
github OriginProtocol / origin / experimental / origin-messaging-client / src / Messaging.js View on Github external
const buffer = CryptoJS.AES.decrypt(msg, key, {
      iv: CryptoJS.enc.Base64.parse(iv_str)
    })
    let out_text
    try {
      out_text = buffer.toString(CryptoJS.enc.Utf8)
    } catch (error) {
      return
    }

    if (out_text && out_text.length > 6) {
      const verify_text = out_text.slice(0, -6)
      const sha_check = out_text.substr(-6)
      if (
        sha_check ==
        CryptoJS.enc.Base64.stringify(CryptoJS.SHA1(verify_text)).substr(0, 6)
      ) {
        return verify_text
      }
    }
  }
github OriginProtocol / origin / origin-messaging-client / src / Messaging.js View on Github external
const buffer = CryptoJS.AES.decrypt(msg, key, {
      iv: CryptoJS.enc.Base64.parse(ivStr)
    })
    let outText
    try {
      outText = buffer.toString(CryptoJS.enc.Utf8)
    } catch (error) {
      return
    }

    if (outText && outText.length > 6) {
      const verifyText = outText.slice(0, -6)
      const shaCheck = outText.substr(-6)
      if (
        shaCheck ==
        CryptoJS.enc.Base64.stringify(CryptoJS.SHA1(verifyText)).substr(0, 6)
      ) {
        return verifyText
      }
    }
  }
github OfficeDev / script-lab-2017 / src / app / services / snippet.ts View on Github external
private _generateHash(): string {
        if (_.isEmpty(this.content)) {
            throw new PlaygroundError('Snippet hash failed. Cannot create hash of null or undefined');
        }

        return crypto.SHA1(JSON.stringify(this.content)).toString();
    }
}
github Loxone / lxcommunicator / vendor / CryptoAdapter.js View on Github external
CryptoAdapter.SHA1 = function SHA1(message) {
        return CryptoJS.SHA1(message).toString();
    };
github oddbit / tanam / functions / src / services / system-message.service.ts View on Github external
function createNoficication(type: SystemNotificationType, title: string, message: string) {
    const id = SHA1(type + title + message).toString().toLowerCase();
    const docRef = siteCollection().collection('notifications').doc(id);

    return admin.firestore().runTransaction(async (trx) => {
        const trxNotifDoc = await trx.get(docRef);
        if (trxNotifDoc.exists) {
            trx.update(docRef, {
                updated: admin.firestore.FieldValue.serverTimestamp(),
                numOccurances: admin.firestore.FieldValue.increment(1),
                isRead: false,
            } as SystemNotification);
        } else {
            trx.set(docRef, {
                id: id,
                type: 'error',
                title: title,
                message: message,
github adlnet / xAPIWrapper / src / Utils.js View on Github external
toSHA1(text) {
        if (CryptoJS && CryptoJS.SHA1)
            return CryptoJS.SHA1(text).toString();
        else
            return Crypto.util.bytesToHex(Crypto.SHA1(text, { asBytes: true }));
    }