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


Java SCrypt类代码示例

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


SCrypt类属于com.lambdaworks.crypto包,在下文中一共展示了SCrypt类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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包/类
@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.warn("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:bither,项目名称:bitherj,代码行数:26,代码来源:KeyCrypterScrypt.java

示例6: bip38Stretch1

import com.lambdaworks.crypto.SCrypt; //导入依赖的package包/类
/**
 * Perform BIP38 compatible password stretching on a password to derive the
 * BIP38 key material
 *
 * @throws InterruptedException
 */
public static byte[] bip38Stretch1(CharSequence passphrase, byte[] salt, int outputSize)
        throws InterruptedException {
    byte[] passwordBytes = null;
    byte[] derived;
    try {
        passwordBytes = convertToByteArray(passphrase);
        derived = SCrypt.scrypt(convertToByteArray(passphrase), salt, SCRYPT_N, SCRYPT_R, SCRYPT_P, outputSize
        );
        return derived;
    } catch (GeneralSecurityException e) {
        throw new RuntimeException(e);
    } finally {
        // Zero the password bytes.
        if (passwordBytes != null) {
            java.util.Arrays.fill(passwordBytes, (byte) 0);
        }
    }
}
 
开发者ID:bither,项目名称:bitherj,代码行数:25,代码来源:Bip38.java

示例7: 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

示例8: 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


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