Search in sources :

Example 91 with KeyParameter

use of org.bouncycastle.crypto.params.KeyParameter in project bitcoin-wallet by bitcoin-wallet.

the class RaiseFeeDialogFragment method handleGo.

private void handleGo() {
    state = State.DECRYPTING;
    updateView();
    final Wallet wallet = walletActivityViewModel.wallet.getValue();
    if (wallet.isEncrypted()) {
        new DeriveKeyTask(backgroundHandler, application.scryptIterationsTarget()) {

            @Override
            protected void onSuccess(final KeyParameter encryptionKey, final boolean wasChanged) {
                if (wasChanged)
                    WalletUtils.autoBackupWallet(activity, wallet);
                doRaiseFee(wallet, encryptionKey);
            }
        }.deriveKey(wallet, passwordView.getText().toString().trim());
        updateView();
    } else {
        doRaiseFee(wallet, null);
    }
}
Also used : Wallet(org.bitcoinj.wallet.Wallet) KeyParameter(org.bouncycastle.crypto.params.KeyParameter)

Example 92 with KeyParameter

use of org.bouncycastle.crypto.params.KeyParameter in project openremote by openremote.

the class SecureUtils method decryptCCM.

public static byte[] decryptCCM(@NotNull final byte[] data, @NotNull final byte[] key, @NotNull final byte[] nonce, @NotNull final byte[] additionalData, final int micSize) throws InvalidCipherTextException {
    Objects.requireNonNull(data);
    Objects.requireNonNull(key);
    Objects.requireNonNull(nonce);
    Objects.requireNonNull(additionalData);
    final byte[] ccm = new byte[data.length - micSize];
    final CCMBlockCipher ccmBlockCipher = new CCMBlockCipher(new AESEngine());
    final AEADParameters aeadParameters = new AEADParameters(new KeyParameter(key), micSize * 8, nonce, additionalData);
    ccmBlockCipher.init(false, aeadParameters);
    ccmBlockCipher.processBytes(data, 0, data.length, ccm, 0);
    ccmBlockCipher.doFinal(ccm, 0);
    return ccm;
}
Also used : AESEngine(org.bouncycastle.crypto.engines.AESEngine) AEADParameters(org.bouncycastle.crypto.params.AEADParameters) KeyParameter(org.bouncycastle.crypto.params.KeyParameter) CCMBlockCipher(org.bouncycastle.crypto.modes.CCMBlockCipher)

Example 93 with KeyParameter

use of org.bouncycastle.crypto.params.KeyParameter in project openremote by openremote.

the class SecureUtils method calculateCMAC.

public static byte[] calculateCMAC(final byte[] data, final byte[] key) {
    final byte[] cmac = new byte[16];
    CipherParameters cipherParameters = new KeyParameter(key);
    BlockCipher blockCipher = new AESEngine();
    CMac mac = new CMac(blockCipher);
    mac.init(cipherParameters);
    mac.update(data, 0, data.length);
    mac.doFinal(cmac, 0);
    return cmac;
}
Also used : CipherParameters(org.bouncycastle.crypto.CipherParameters) AESEngine(org.bouncycastle.crypto.engines.AESEngine) CMac(org.bouncycastle.crypto.macs.CMac) BlockCipher(org.bouncycastle.crypto.BlockCipher) CCMBlockCipher(org.bouncycastle.crypto.modes.CCMBlockCipher) KeyParameter(org.bouncycastle.crypto.params.KeyParameter)

Example 94 with KeyParameter

use of org.bouncycastle.crypto.params.KeyParameter in project openremote by openremote.

the class SecureUtils method encryptWithAES.

public static byte[] encryptWithAES(final byte[] data, final byte[] key) {
    final byte[] encrypted = new byte[data.length];
    final CipherParameters cipherParameters = new KeyParameter(key);
    final AESLightEngine engine = new AESLightEngine();
    engine.init(true, cipherParameters);
    engine.processBlock(data, 0, encrypted, 0);
    return encrypted;
}
Also used : CipherParameters(org.bouncycastle.crypto.CipherParameters) KeyParameter(org.bouncycastle.crypto.params.KeyParameter) AESLightEngine(org.bouncycastle.crypto.engines.AESLightEngine)

Example 95 with KeyParameter

use of org.bouncycastle.crypto.params.KeyParameter in project bitcoin-wallet by bitcoin-wallet.

the class SendCoinsFragment method handleGo.

private void handleGo() {
    privateKeyBadPasswordView.setVisibility(View.INVISIBLE);
    final Wallet wallet = walletActivityViewModel.wallet.getValue();
    if (wallet.isEncrypted()) {
        new DeriveKeyTask(backgroundHandler, application.scryptIterationsTarget()) {

            @Override
            protected void onSuccess(final KeyParameter encryptionKey, final boolean wasChanged) {
                if (wasChanged)
                    WalletUtils.autoBackupWallet(activity, wallet);
                signAndSendPayment(encryptionKey);
            }
        }.deriveKey(wallet, privateKeyPasswordView.getText().toString().trim());
        setState(SendCoinsViewModel.State.DECRYPTING);
    } else {
        signAndSendPayment(null);
    }
}
Also used : Wallet(org.bitcoinj.wallet.Wallet) KeyParameter(org.bouncycastle.crypto.params.KeyParameter)

Aggregations

KeyParameter (org.bouncycastle.crypto.params.KeyParameter)119 ParametersWithIV (org.bouncycastle.crypto.params.ParametersWithIV)51 AESEngine (org.bouncycastle.crypto.engines.AESEngine)37 CipherParameters (org.bouncycastle.crypto.CipherParameters)35 GCMBlockCipher (org.bouncycastle.crypto.modes.GCMBlockCipher)24 AEADParameters (org.bouncycastle.crypto.params.AEADParameters)22 CBCBlockCipher (org.bouncycastle.crypto.modes.CBCBlockCipher)21 PaddedBufferedBlockCipher (org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher)21 IvParameterSpec (javax.crypto.spec.IvParameterSpec)19 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)16 InvalidCipherTextException (org.bouncycastle.crypto.InvalidCipherTextException)16 AEADBlockCipher (org.bouncycastle.crypto.modes.AEADBlockCipher)16 InvalidKeyException (java.security.InvalidKeyException)13 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)12 SecretKeySpec (javax.crypto.spec.SecretKeySpec)12 BufferedBlockCipher (org.bouncycastle.crypto.BufferedBlockCipher)12 PKCS5S2ParametersGenerator (org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator)12 SecureRandom (java.security.SecureRandom)11 SecretKey (javax.crypto.SecretKey)10 BlockCipher (org.bouncycastle.crypto.BlockCipher)8