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


Java KeyCrypter类代码示例

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


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

示例1: changePasscode

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
public void changePasscode(KeyParameter oldAesKey,
                           KeyCrypter keyCrypter,
                           KeyParameter aesKey) {
    mLogger.info("changePasscode starting");

    // Change the parameters on our HDReceiver.
    // mHDReceiver.setPersistCrypter(keyCrypter, aesKey);
    mHDReceiver.persist();

    mLogger.info("persisted HD wallet");

    // Decrypt the wallet with the old key.
    mKit.wallet().decrypt(oldAesKey);

    mLogger.info("decrypted base wallet");

    // Encrypt the wallet using the new key.
    mKit.wallet().encrypt(keyCrypter, aesKey);

    mLogger.info("reencrypted base wallet");
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:22,代码来源:WalletService.java

示例2: encrypt

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
/**
 * Convenience wrapper around {@link Wallet#encrypt(com.google.bitcoin.crypto.KeyCrypter,
 * org.spongycastle.crypto.params.KeyParameter)} which uses the default Scrypt key derivation algorithm and
 * parameters, derives a key from the given password and returns the created key.
 */
public KeyParameter encrypt(CharSequence password) {
    checkNotNull(password);
    checkArgument(password.length() > 0);
    KeyCrypter scrypt = new KeyCrypterScrypt();
    KeyParameter derivedKey = scrypt.deriveKey(password);
    encrypt(scrypt, derivedKey);
    return derivedKey;
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:14,代码来源:Wallet.java

示例3: decrypt

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
/**
 * Create a decrypted private key with the keyCrypter and AES key supplied. Note that if the aesKey is wrong, this
 * has some chance of throwing KeyCrypterException due to the corrupted padding that will result, but it can also
 * just yield a garbage key.
 *
 * @param keyCrypter The keyCrypter that specifies exactly how the decrypted bytes are created.
 * @param aesKey The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached).
 * @return unencryptedKey
 */
public ECKey decrypt(KeyCrypter keyCrypter, KeyParameter aesKey) throws KeyCrypterException {
    Preconditions.checkNotNull(keyCrypter);
    // Check that the keyCrypter matches the one used to encrypt the keys, if set.
    if (this.keyCrypter != null && !this.keyCrypter.equals(keyCrypter)) {
        throw new KeyCrypterException("The keyCrypter being used to decrypt the key is different to the one that was used to encrypt it");
    }
    byte[] unencryptedPrivateKey = keyCrypter.decrypt(encryptedPrivateKey, aesKey);
    ECKey key = new ECKey(new BigInteger(1, unencryptedPrivateKey), null, isCompressed());
    if (!Arrays.equals(key.getPubKey(), getPubKey()))
        throw new KeyCrypterException("Provided AES key is wrong");
    return key;
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:22,代码来源:ECKey.java

示例4: setKeyCrypter

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
/**
 * Sets the wallet's KeyCrypter.
 * Note that this does not encrypt the wallet, and should only be used if the keyCrypter can not be included in the
 * constructor during initial wallet loading.
 * Note that if the keyCrypter was not properly set during wallet load, {@link Wallet#getEncryptionType()} and
 * {@link Wallet#isEncrypted()} will not return the correct results.
 */
public void setKeyCrypter(KeyCrypter keyCrypter) {
    lock.lock();
    try {
        checkState(this.keyCrypter == null);
        this.keyCrypter = keyCrypter;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:17,代码来源:Wallet.java

示例5: encryptionDecryptionHomogenousKeys

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
@Test
public void encryptionDecryptionHomogenousKeys() throws Exception {
    // Check the wallet is currently encrypted
    assertTrue("Wallet is not an encrypted wallet", encryptedWallet.getEncryptionType() == EncryptionType.ENCRYPTED_SCRYPT_AES);

    // Try added an ECKey that was encrypted with a differenct ScryptParameters (i.e. a non-homogenous key).
    // This is not allowed as the ScryptParameters is stored at the Wallet level.
    byte[] salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
    secureRandom.nextBytes(salt);
    Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(salt));
    ScryptParameters scryptParameters = scryptParametersBuilder.build();

    KeyCrypter keyCrypterDifferent = new KeyCrypterScrypt(scryptParameters);

    ECKey ecKeyDifferent = new ECKey();
    ecKeyDifferent = ecKeyDifferent.encrypt(keyCrypterDifferent, aesKey);

    Iterable<ECKey> keys = encryptedWallet.getKeys();
    Iterator iterator = keys.iterator();
    boolean oneKey = iterator.hasNext();
    iterator.next();
    assertTrue("Wrong number of keys in wallet before key addition", oneKey && !iterator.hasNext());

    try {
        encryptedWallet.addKey(ecKeyDifferent);
        fail("AddKey should have thrown an EncrypterDecrypterException but did not.");
    } catch (KeyCrypterException ede) {
        // Expected behaviour.
    }

    keys = encryptedWallet.getKeys();
    iterator = keys.iterator();
    oneKey = iterator.hasNext();

    iterator.next();
    assertTrue("Wrong number of keys in wallet after key addition", oneKey && !iterator.hasNext());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:38,代码来源:WalletTest.java

示例6: getKeyCrypter

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
/**
 * Get the wallet's KeyCrypter.
 * (Used in encrypting/ decrypting an ECKey).
 */
public KeyCrypter getKeyCrypter() {
    lock.lock();
    try {
        return keyCrypter;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:13,代码来源:Wallet.java

示例7: encryptionIsReversible

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
/**
 * Check that it is possible to decrypt the key with the keyCrypter and that the original key is returned.
 *
 * Because it is a critical failure if the private keys cannot be decrypted successfully (resulting of loss of all bitcoins controlled
 * by the private key) you can use this method to check when you *encrypt* a wallet that it can definitely be decrypted successfully.
 * See {@link Wallet#encrypt(KeyCrypter keyCrypter, KeyParameter aesKey)} for example usage.
 *
 * @return true if the encrypted key can be decrypted back to the original key successfully.
 */
public static boolean encryptionIsReversible(ECKey originalKey, ECKey encryptedKey, KeyCrypter keyCrypter, KeyParameter aesKey) {
    String genericErrorText = "The check that encryption could be reversed failed for key " + originalKey.toString() + ". ";
    try {
        ECKey rebornUnencryptedKey = encryptedKey.decrypt(keyCrypter, aesKey);
        if (rebornUnencryptedKey == null) {
            log.error(genericErrorText + "The test decrypted key was missing.");
            return false;
        }
        
        byte[] originalPrivateKeyBytes = originalKey.getPrivKeyBytes();
        if (originalPrivateKeyBytes != null) {
            if (rebornUnencryptedKey.getPrivKeyBytes() == null) {
                log.error(genericErrorText + "The test decrypted key was missing.");
                return false;
            } else {
                if (originalPrivateKeyBytes.length != rebornUnencryptedKey.getPrivKeyBytes().length) {
                    log.error(genericErrorText + "The test decrypted private key was a different length to the original.");
                    return false;
                } else {
                    for (int i = 0; i < originalPrivateKeyBytes.length; i++) {
                        if (originalPrivateKeyBytes[i] != rebornUnencryptedKey.getPrivKeyBytes()[i]) {
                            log.error(genericErrorText + "Byte " + i + " of the private key did not match the original.");
                            return false;
                        }
                    }
                }
            }
        }
    } catch (KeyCrypterException kce) {
        log.error(kce.getMessage());
        return false;
    }
    
    // Key can successfully be decrypted.
    return true;
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:46,代码来源:ECKey.java

示例8: setPasscode

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
public static void setPasscode(Context context,
                               WalletService walletService,
                               String passcode,
                               boolean isChange) {

    WalletApplication wallapp =
        (WalletApplication) context.getApplicationContext();

    KeyParameter oldAesKey = wallapp.mAesKey;

    mLogger.info("setPasscode starting");

    byte[] salt;
    if (isChange) {
        // Reuse our salt (better chance of recovering if
        // we are between passcode values).
        salt = readSalt(context);
    } else {
        // Create salt and write to file.
        SecureRandom secureRandom = new SecureRandom();
        salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
        secureRandom.nextBytes(salt);
        writeSalt(context, salt);
    }

    KeyCrypter keyCrypter = getKeyCrypter(salt);
    KeyParameter aesKey = keyCrypter.deriveKey(passcode);

    if (isChange) {
        walletService.changePasscode(oldAesKey, keyCrypter, aesKey);
    }

    // Set up the application context with credentials.
    wallapp.mPasscode = passcode;
    wallapp.mKeyCrypter = keyCrypter;
    wallapp.mAesKey = aesKey;

    mLogger.info("setPasscode finished");
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:40,代码来源:WalletUtil.java

示例9: MyWalletAppKit

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
public MyWalletAppKit(NetworkParameters params, File directory, String filePrefix, KeyCrypter keyCrypter, long scanTime) {
    this.params = checkNotNull(params);
    this.directory = checkNotNull(directory);
    this.filePrefix = checkNotNull(filePrefix);
    this.keyCrypter = keyCrypter;
    this.scanTime = scanTime;
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:8,代码来源:MyWalletAppKit.java

示例10: gatherAllKeys

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
public void gatherAllKeys(KeyCrypter keyCrypter,
                          KeyParameter aesKey,
                          long creationTime,
                          List<ECKey> keys) {
    mReceiveChain.gatherAllKeys(keyCrypter, aesKey, creationTime, keys);
    mChangeChain.gatherAllKeys(keyCrypter, aesKey, creationTime, keys);
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:8,代码来源:HDAccount.java

示例11: ensureMargins

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
public int ensureMargins(Wallet wallet,
                          KeyCrypter keyCrypter,
                          KeyParameter aesKey) {
    int receiveAdded =
        mReceiveChain.ensureMargins(wallet, keyCrypter, aesKey);
    int changeAdded =
        mChangeChain.ensureMargins(wallet, keyCrypter, aesKey);

    return (receiveAdded > changeAdded) ? receiveAdded : changeAdded;
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:11,代码来源:HDAccount.java

示例12: restore

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
public static HDReceiver restore(Context ctxt,
                                 NetworkParameters params,
                                 File directory,
                                 String filePrefix,
                                 KeyCrypter keyCrypter,
                                 KeyParameter aesKey)
    throws InvalidCipherTextException, IOException {

    try {
        JSONObject node = deserialize(directory, filePrefix);

        return new HDReceiver(ctxt, params, directory, filePrefix, node);
    }
    catch (JSONException ex) {
        String msg = "trouble deserializing wallet: " + ex.toString();

        // Have to break the message into chunks for big messages ...
        while (msg.length() > 1024) {
            String chunk = msg.substring(0, 1024);
            mLogger.error(chunk);
            msg = msg.substring(1024);
        }
        mLogger.error(msg);

        throw new RuntimeException(msg);
    }
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:28,代码来源:HDReceiver.java

示例13: gatherKey

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
public void gatherKey(KeyCrypter keyCrypter,
                      KeyParameter aesKey,
                      long creationTime,
                      List<ECKey> keys) {
    mECKey.setCreationTimeSeconds(creationTime);
    if (keyCrypter == null)
        keys.add(mECKey);
    else
        keys.add(mECKey.encrypt(keyCrypter, aesKey));
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:11,代码来源:HDAddress.java

示例14: gatherAllKeys

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
public void gatherAllKeys(KeyCrypter keyCrypter,
                          KeyParameter aesKey,
                          long creationTime,
                          List<ECKey> keys) {
    for (HDAddress hda : mAddrs)
        hda.gatherKey(keyCrypter, aesKey, creationTime, keys);
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:8,代码来源:HDChain.java

示例15: ensureMargins

import com.google.bitcoin.crypto.KeyCrypter; //导入依赖的package包/类
public int ensureMargins(Wallet wallet,
                         KeyCrypter keyCrypter,
                         KeyParameter aesKey) {
    // How many unused addresses do we have at the end of the chain?
    int numUnused = marginSize();

    // Do we have an ample margin?
    if (numUnused >= DESIRED_MARGIN) {
        return 0;
    }
    else {
        // How many addresses do we need to add?
        int numAdd = DESIRED_MARGIN - numUnused;

        mLogger.info(String.format("%s expanding margin, adding %d addrs",
                                   mChainKey.getPath(), numAdd));

        // Set the new keys creation time to now.
        long now = Utils.now().getTime() / 1000;

        // Add the addresses ...
        int newSize = mAddrs.size() + numAdd;
        ArrayList<ECKey> keys = new ArrayList<ECKey>();
        for (int ii = mAddrs.size(); ii < newSize; ++ii) {
            HDAddress hda = new HDAddress(mParams, mChainKey, ii);
            mAddrs.add(hda);
            hda.gatherKey(keyCrypter, aesKey, now, keys);
        }
        mLogger.info(String.format("adding %d keys", keys.size()));
        wallet.addKeys(keys);

        return numAdd;
    }
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:35,代码来源:HDChain.java


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