How to use the crypto-js.SHA256 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 NewEconoLab / NeoWalletForWeChat / src / lib / neo-ts / Helper / AccountHelper.js View on Github external
static GetNep2FromPrivateKey(prikey, passphrase, n = 16384, r = 8, p = 8, callback) {
        let that = this;
        var pubkey = Helper.GetPublicKeyFromPrivateKey(prikey);
        let addr = Helper.GetAddressFromPublicKey(pubkey);
        const strkey = SHA256(SHA256(addr).toString()).toString().slice(0, 4);
        let uint8pass = this.String2Bytes(passphrase);
        console.log('strkey = ' + prikey);
        scrypt.default(uint8pass, strkey, {
            logN: 5,
            r: r,
            p: p,
            dkLen: 64,
            interruptStep: 1000,
            encoding: 'hash'
        }, function (res) {
            var u8dk = new Uint8Array(res);
            var derivedhalf1 = u8dk.subarray(0, 32);
            var derivedhalf2 = u8dk.subarray(32, 64);
            var u8xor = new Uint8Array(32);
            for (var i = 0; i < 32; i++) {
                u8xor[i] = prikey[i] ^ derivedhalf1[i];
github CityOfZion / neon-wallet / app / util / Passphrase.js View on Github external
const decrypt = (encryptedKey, keyphrase, progressCallback) => {
    const assembled = ab2hexstring(bs58check.decode(encryptedKey))
    const addressHash = assembled.substr(6, 8)
    const encrypted = assembled.substr(-64)
    const derived = scrypt.hashSync(Buffer.from(keyphrase, 'utf8'), Buffer.from(addressHash, 'hex'), scrypt_options, progressCallback).toString('hex')
    const derived1 = derived.slice(0, 64)
    const derived2 = derived.slice(64)
    const ciphertext = { ciphertext: enc.Hex.parse(encrypted), salt: "" }
    const decrypted = AES.decrypt(ciphertext, enc.Hex.parse(derived2), { mode: C.mode.ECB, padding: C.pad.NoPadding })
    const privateKey = hexXor(decrypted.toString(), derived1)
    console.log("private key dec", privateKey);
    const address = getAccountsFromPrivateKey(privateKey)[0].address
    const newAddressHash = SHA256(SHA256(enc.Latin1.parse(address))).toString().slice(0, 8)
    if (addressHash !== newAddressHash) throw new Error("Wrong Password!")
    return getWIFFromPrivateKey(Buffer.from(privateKey, 'hex'));
};
github lagmoellertim / cryption / src / worker / handleFiles.js View on Github external
export const getSHA256 = async (value) => {
    return await CryptoJS.SHA256(value).toString();
}
github ontio / ontology-ts-sdk / src / transaction / transaction.ts View on Github external
getSignContent() {
        const data = this.serializeUnsignedData();

        const ProgramHexString = cryptoJS.enc.Hex.parse(data);
        const ProgramSha256 = cryptoJS.SHA256(ProgramHexString).toString();
        const ProgramSha2562 = cryptoJS.SHA256(cryptoJS.enc.Hex.parse(ProgramSha256)).toString();

        return ProgramSha2562;
    }
github vedmant / my-little-bitcoin / src / lib / block.js View on Github external
function calculateHash ({index, prevHash, time, transactions, nonce}) {
  return CryptoJS.SHA256(JSON.stringify({index, prevHash, time, transactions, nonce})).toString()
}
github snowypowers / ansy / src / modules / nep2.js View on Github external
decrypt: (encryptedKey, keyphrase, progressCallback) => {
    const assembled = toHexString(bs58check.decode(encryptedKey))
    const addressHash = assembled.substr(6, 8)
    const encrypted = assembled.substr(-64)
    const derived = scrypt(Buffer.from(keyphrase, 'utf8'), Buffer.from(addressHash, 'hex'), 16384, 8, 8, 64, progressCallback).toString('hex')
    const derived1 = derived.slice(0, 64)
    const derived2 = derived.slice(64)
    const ciphertext = { ciphertext: enc.Hex.parse(encrypted), salt: "" }
    const decrypted = AES.decrypt(ciphertext, enc.Hex.parse(derived2), { mode: C.mode.ECB, padding: C.pad.NoPadding })
    const privateKey = hexXor(decrypted.toString(), derived1)
    const address = crypto.getAddrFromPri(privateKey)
    const newAddressHash = SHA256(SHA256(enc.Latin1.parse(address))).toString().slice(0, 8)
    if (addressHash !== newAddressHash) throw new Error("Wrong Password!")
    return privateKey
  }
}
github LimeChain / eoslime / src / helpers / crypto.js View on Github external
hash: function (data) {
        try {
            let dataHash = cryptoJS.SHA256(data).toString(cryptoJS.enc.Hex);
            return dataHash;
        } catch (error) {
            throw new Error('Couldn\'t hash the data')
        }
    },
    encrypt: function (data, password) {
github adlnet / xAPIWrapper / src / Utils.js View on Github external
toSHA256(text) {
        if (CryptoJS && CryptoJS.SHA256)
            return CryptoJS.SHA256(text).toString();
    }
github lukepark327 / onechain / 3_pow / blockchain.js View on Github external
function calculateHash(index, previousHash, timestamp, data, difficulty, nonce) {
    return CryptoJS.SHA256(index + previousHash + timestamp + data + difficulty + nonce).toString();
}
github nknorg / nkn / dashboard / web / helpers / crypto.js View on Github external
export function tripleSha256(str) {
  return CryptoJS.SHA256(CryptoJS.SHA256(CryptoJS.SHA256(str))).toString()
}