当前位置: 首页>>代码示例>>Java>>正文


Java SCrypt.scrypt方法代码示例

本文整理汇总了Java中com.lambdaworks.crypto.SCrypt.scrypt方法的典型用法代码示例。如果您正苦于以下问题:Java SCrypt.scrypt方法的具体用法?Java SCrypt.scrypt怎么用?Java SCrypt.scrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.lambdaworks.crypto.SCrypt的用法示例。


在下文中一共展示了SCrypt.scrypt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decryptNoEC

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
private ECKey decryptNoEC(String normalizedPassphrase) {
    try {
        byte[] derived = SCrypt.scrypt(normalizedPassphrase.getBytes(Charsets.UTF_8), addressHash, 16384, 8, 8, 64);
        byte[] key = Arrays.copyOfRange(derived, 32, 64);
        SecretKeySpec keyspec = new SecretKeySpec(key, "AES");

        DRMWorkaround.maybeDisableExportControls();
        Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");

        cipher.init(Cipher.DECRYPT_MODE, keyspec);
        byte[] decrypted = cipher.doFinal(content, 0, 32);
        for (int i = 0; i < 32; i++)
            decrypted[i] ^= derived[i];
        return ECKey.fromPrivate(decrypted, compressed);
    } catch (GeneralSecurityException x) {
        throw new RuntimeException(x);
    }
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:19,代码来源:BIP38PrivateKey.java

示例2: deriveKey

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
/**
 * Generate AES key.
 *
 * This is a very slow operation compared to encrypt/ decrypt so it is normally worth caching the result.
 *
 * @param password    The password to use in key generation
 * @return            The KeyParameter containing the created AES key
 * @throws            KeyCrypterException
 */
@Override
public KeyParameter deriveKey(CharSequence password) throws KeyCrypterException {
    byte[] passwordBytes = null;
    try {
        passwordBytes = convertToByteArray(password);
        byte[] salt = new byte[0];
        if ( scryptParameters.getSalt() != null) {
            salt = scryptParameters.getSalt().toByteArray();
        } else {
            // Warn the user that they are not using a salt.
            // (Some early MultiBit wallets had a blank salt).
            log.warn("You are using a ScryptParameters with no salt. Your encryption may be vulnerable to a dictionary attack.");
        }

        byte[] keyBytes = SCrypt.scrypt(passwordBytes, salt, (int) scryptParameters.getN(), scryptParameters.getR(), scryptParameters.getP(), KEY_LENGTH);
        return new KeyParameter(keyBytes);
    } catch (Exception e) {
        throw new KeyCrypterException("Could not generate key from password and salt.", e);
    } finally {
        // Zero the password bytes.
        if (passwordBytes != null) {
            java.util.Arrays.fill(passwordBytes, (byte) 0);
        }
    }
}
 
开发者ID:appteam-nith,项目名称:NithPointsj,代码行数:35,代码来源:KeyCrypterScrypt.java

示例3: decryptBip38NoEC

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
private ECKey decryptBip38NoEC(String normalizedPassphrase) {
    try {
        byte[] derived = SCrypt.scrypt(normalizedPassphrase.getBytes(Charsets.UTF_8), addressHash, 16384, 8, 8, 64);
        byte[] key = Arrays.copyOfRange(derived, 32, 64);
        SecretKeySpec keyspec = new SecretKeySpec(key, "AES");

        DRMWorkaround.maybeDisableExportControls();
        Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");

        cipher.init(Cipher.DECRYPT_MODE, keyspec);
        byte[] decrypted = cipher.doFinal(content, 0, 32);
        for (int i = 0; i < 32; i++)
            decrypted[i] ^= derived[i];
        return ECKey.fromPrivate(decrypted, compressed);
    } catch (GeneralSecurityException x) {
        throw new RuntimeException(x);
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:19,代码来源:SerializedKey.java

示例4: deriveKey

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
@Override
public KeyParameter deriveKey(CharSequence password) throws KeyCrypterException {
    byte[] passwordBytes = null;
    try {
        passwordBytes = convertToByteArray(password);
        byte[] salt = new byte[0];
        if (mSalt != null) {
            salt = mSalt;
        } else {
            // Warn the user that they are not using a salt.
            // (Some early MultiBit wallets had a blank salt).
            Log.w(TAG, "You are using a ScryptParameters with no salt. Your encryption may be vulnerable to a dictionary attack.");
        }

        byte[] keyBytes = SCrypt.scrypt(passwordBytes, salt, BITCOINJ_SCRYPT_N, BITCOINJ_SCRYPT_R, BITCOINJ_SCRYPT_P, KEY_LENGTH);
        return new KeyParameter(keyBytes);
    } catch (Exception e) {
        throw new KeyCrypterException("Could not generate key from password and salt.", e);
    } finally {
        // Zero the password bytes.
        if (passwordBytes != null) {
            java.util.Arrays.fill(passwordBytes, (byte) 0);
        }
    }
}
 
开发者ID:chaincloud-dot-com,项目名称:chaincloud-v,代码行数:26,代码来源:KeyCrypterScrypt.java

示例5: deriveKey

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
/**
 * Generate AES key.
 * <p/>
 * This is a very slow operation compared to encrypt/ decrypt so it is normally worth caching the result.
 *
 * @param password The password to use in key generation
 * @return The KeyParameter containing the created AES key
 * @throws KeyCrypterException
 */
@Override
public KeyParameter deriveKey(CharSequence password) throws KeyCrypterException {
    byte[] passwordBytes = null;
    try {
        passwordBytes = convertToByteArray(password);
        byte[] salt = new byte[0];
        if (scryptParameters.getSalt() != null) {
            salt = scryptParameters.getSalt().toByteArray();
        } else {
            // Warn the user that they are not using a salt.
            // (Some early MultiBit wallets had a blank salt).
            log.warn("You are using a ScryptParameters with no salt. Your encryption may be vulnerable to a dictionary attack.");
        }

        byte[] keyBytes = SCrypt.scrypt(passwordBytes, salt, (int) scryptParameters.getN(), scryptParameters.getR(), scryptParameters.getP(), KEY_LENGTH);
        return new KeyParameter(keyBytes);
    } catch (Exception e) {
        throw new KeyCrypterException("Could not generate key from password and salt.", e);
    } finally {
        // Zero the password bytes.
        if (passwordBytes != null) {
            java.util.Arrays.fill(passwordBytes, (byte) 0);
        }
    }
}
 
开发者ID:goldcoin,项目名称:goldcoin-android,代码行数:35,代码来源:KeyCrypterScrypt.java

示例6: deriveKey

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
/**
 * Generate AES key.
 *
 * This is a very slow operation compared to encrypt/ decrypt so it is normally worth caching the result.
 *
 * @param password    The password to use in key generation
 * @return            The KeyParameter containing the created AES key
 * @throws            KeyCrypterException
 */
@Override
public KeyParameter deriveKey(CharSequence password) throws KeyCrypterException {
    byte[] passwordBytes = null;
    try {
        passwordBytes = convertToByteArray(password);
        byte[] salt = new byte[0];
        if ( scryptParameters.getSalt() != null) {
            salt = scryptParameters.getSalt().toByteArray();
        } else {
            // Warn the user that they are not using a salt.
            // (Some early MultiBit wallets had a blank salt).
            log.warn("You are using a ScryptParameters with no salt. Your encryption may be vulnerable to a dictionary attack.");
        }

        final Stopwatch watch = Stopwatch.createStarted();
        byte[] keyBytes = SCrypt.scrypt(passwordBytes, salt, (int) scryptParameters.getN(), scryptParameters.getR(), scryptParameters.getP(), KEY_LENGTH);
        watch.stop();
        log.info("Deriving key took {} for {} scrypt iterations.", watch, scryptParameters.getN());
        return new KeyParameter(keyBytes);
    } catch (Exception e) {
        throw new KeyCrypterException("Could not generate key from password and salt.", e);
    } finally {
        // Zero the password bytes.
        if (passwordBytes != null) {
            java.util.Arrays.fill(passwordBytes, (byte) 0);
        }
    }
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:38,代码来源:KeyCrypterScrypt.java

示例7: generateKey

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
public ECKey generateKey() throws GeneralSecurityException, UnsupportedEncodingException {
    final String composedKey = username + ":" + password + ":tatualado";
    byte[] hash = SCrypt.scrypt(composedKey.getBytes("UTF-8"),
    new String("Uzy7pjlwDkwIWuq").getBytes("UTF-8"),
            32768, 4, 1, 32);

    ECKey generatedKey = ECKey.fromPrivate(hash, false);
    return generatedKey;
}
 
开发者ID:btcbrdev,项目名称:bitcoin-otc-wot-for-the-lazy,代码行数:10,代码来源:KeyDerivator.java

示例8: getSeed

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
public byte[] getSeed(String salt, String password) {
    try {
        byte[] seed = SCrypt.scrypt(
                CryptoUtils.decodeAscii(password),
                CryptoUtils.decodeAscii(salt),
                SCRYPT_PARAMS_N, SCRYPT_PARAMS_r,
                SCRYPT_PARAMS_p, SEED_BYTES);
        return seed;
    } catch (GeneralSecurityException e) {
        e.printStackTrace();
        throw new UCoinTechnicalException(
                "Unable to salt password, using Scrypt library", e);
    }
}
 
开发者ID:duniter,项目名称:duniter-android-app,代码行数:15,代码来源:CryptoService.java

示例9: hash

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
/**
 * Derives a cryptographic hash using {@code SCrypt}.
 * This function can be compute intensive.
 *
 * @param domain        The domain for which the password is used.
 * @param password      The master password from which to derive other passwords.
 * @param configuration Configuration for SCrypt.
 * @return a cryptographically secure hash, in integer form.
 */
private static BigInteger hash(byte[] domain, byte[] password, Configuration configuration) {
    try {
        byte[] salt = configuration.code.getBytes();
        // Concatenating the password and salt.
        byte[] passwordCode = new byte[password.length + salt.length];
        System.arraycopy(password, 0, passwordCode, 0, password.length);
        System.arraycopy(salt, 0, passwordCode, password.length, salt.length);

        // Using SCrypt to get a byte array hash.
        byte[] encrypted = SCrypt.scrypt(
                passwordCode,
                domain,
                (1 << configuration.logN),
                configuration.r,
                configuration.p,
                LENGTH);

        // Converting the byte array to a large integer.
        BigInteger result = BigInteger.ZERO;
        BigInteger factor = BigInteger.ONE;
        BigInteger range = BigInteger.valueOf(256);
        for (int i : encrypted) {
            BigInteger current = BigInteger.valueOf(i & 0xFF).multiply(factor);
            result = result.add(current);
            factor = factor.multiply(range);
        }
        return result;
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid parameters for SCrypt.", e);
    }
}
 
开发者ID:redelmann,项目名称:polymorph-library,代码行数:41,代码来源:Polymorph.java

示例10: scryptDigest

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
public static byte[] scryptDigest(byte[] input) {
    try {
        return SCrypt.scrypt(input, input, 1024, 1, 1, 32);
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:8,代码来源:Utils.java

示例11: scryptDigest

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
/**
 * Calculates the Scrypt hash of the given bytes. This is
 * standard procedure in Mintcoin for hashing blocks.
 * The resulting hash is in big endian form.
 */
public static byte[] scryptDigest(byte[] input) {
try {
    return SCrypt.scrypt(input, input, 1024, 1, 1, 32);
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:keremhd,项目名称:mintcoinj,代码行数:13,代码来源:Utils.java

示例12: scryptDigest

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
public static byte[] scryptDigest(byte[] input) {
try {
    return SCrypt.scrypt(input, input, 1024, 1, 1, 32);
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:pavel4n,项目名称:wowdoge.org,代码行数:8,代码来源:Utils.java

示例13: doSCryptHash

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
protected byte[] doSCryptHash (byte[] password, byte[] salt, int N, int r, int p, int keyLength){
	try {
		return SCrypt.scrypt(password, salt, N, r, p, keyLength);
	} catch (GeneralSecurityException e) {
		e.printStackTrace();
		throw new RuntimeException (e);
	}
}
 
开发者ID:micheal-swiggs,项目名称:jumblar,代码行数:9,代码来源:PhraseGenerator.java

示例14: main

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
        SCryptMetrics m = new SCryptMetrics(new SecureRandom());
        long time = System.currentTimeMillis();
        SCrypt.scrypt(m.password,m.salt,1<<17,2,645,32);
        System.out.println(System.currentTimeMillis() - time);
        m.benchmarkSCrypt(32*1024*1024);
//        int[] params = m.paramsForLowP(60,32*1024*1024);
        int[] params = m.paramsForTimeGivenMemory(60,32*1024*1024);
        System.out.println("try " + params[0] + " " + params[1] + " " + params[2]);
    }
 
开发者ID:karlthepagan,项目名称:SQRL,代码行数:11,代码来源:SCryptMetrics.java

示例15: decryptEC

import com.lambdaworks.crypto.SCrypt; //导入方法依赖的package包/类
private ECKey decryptEC(String normalizedPassphrase) {
    try {
        byte[] ownerEntropy = Arrays.copyOfRange(content, 0, 8);
        byte[] ownerSalt = hasLotAndSequence ? Arrays.copyOfRange(ownerEntropy, 0, 4) : ownerEntropy;

        byte[] passFactorBytes = SCrypt.scrypt(normalizedPassphrase.getBytes(Charsets.UTF_8), ownerSalt, 16384, 8, 8, 32);
        if (hasLotAndSequence) {
            byte[] hashBytes = Bytes.concat(passFactorBytes, ownerEntropy);
            checkState(hashBytes.length == 40);
            passFactorBytes = Sha256Hash.hashTwice(hashBytes);
        }
        BigInteger passFactor = new BigInteger(1, passFactorBytes);
        ECKey k = ECKey.fromPrivate(passFactor, true);

        byte[] salt = Bytes.concat(addressHash, ownerEntropy);
        checkState(salt.length == 12);
        byte[] derived = SCrypt.scrypt(k.getPubKey(), salt, 1024, 1, 1, 64);
        byte[] aeskey = Arrays.copyOfRange(derived, 32, 64);

        SecretKeySpec keyspec = new SecretKeySpec(aeskey, "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
        cipher.init(Cipher.DECRYPT_MODE, keyspec);

        byte[] encrypted2 = Arrays.copyOfRange(content, 16, 32);
        byte[] decrypted2 = cipher.doFinal(encrypted2);
        checkState(decrypted2.length == 16);
        for (int i = 0; i < 16; i++)
            decrypted2[i] ^= derived[i + 16];

        byte[] encrypted1 = Bytes.concat(Arrays.copyOfRange(content, 8, 16), Arrays.copyOfRange(decrypted2, 0, 8));
        byte[] decrypted1 = cipher.doFinal(encrypted1);
        checkState(decrypted1.length == 16);
        for (int i = 0; i < 16; i++)
            decrypted1[i] ^= derived[i];

        byte[] seed = Bytes.concat(decrypted1, Arrays.copyOfRange(decrypted2, 8, 16));
        checkState(seed.length == 24);
        BigInteger seedFactor = new BigInteger(1, Sha256Hash.hashTwice(seed));
        checkState(passFactor.signum() >= 0);
        checkState(seedFactor.signum() >= 0);
        BigInteger priv = passFactor.multiply(seedFactor).mod(ECKey.CURVE.getN());

        return ECKey.fromPrivate(priv, compressed);
    } catch (GeneralSecurityException x) {
        throw new RuntimeException(x);
    }
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:48,代码来源:BIP38PrivateKey.java


注:本文中的com.lambdaworks.crypto.SCrypt.scrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。