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


Java BufferedBlockCipher.doFinal方法代码示例

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


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

示例1: encrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * 加密
 *
 * @param plainBytes
 * @param iv
 * @param aesKey
 * @return EncryptedData
 */
public static EncryptedData encrypt(byte[] plainBytes, byte[] iv, KeyParameter aesKey) throws NulsRuntimeException {
    Utils.checkNotNull(plainBytes);
    Utils.checkNotNull(aesKey);

    try {
        if (iv == null) {
            iv = new byte[16];
            SECURE_RANDOM.nextBytes(iv);
        }

        ParametersWithIV keyWithIv = new ParametersWithIV(aesKey, iv);

        // Encrypt using AES.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(true, keyWithIv);
        byte[] encryptedBytes = new byte[cipher.getOutputSize(plainBytes.length)];
        final int length1 = cipher.processBytes(plainBytes, 0, plainBytes.length, encryptedBytes, 0);
        final int length2 = cipher.doFinal(encryptedBytes, length1);

        return new EncryptedData(iv, Arrays.copyOf(encryptedBytes, length1 + length2));
    } catch (Exception e) {
        throw new NulsRuntimeException(e);
    }
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:33,代码来源:AESEncrypt.java

示例2: decrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * 解密
 *
 * @param dataToDecrypt
 * @param aesKey
 * @return byte[]
 * @throws NulsRuntimeException
 */
public static byte[] decrypt(EncryptedData dataToDecrypt, KeyParameter aesKey) throws NulsRuntimeException {
    Utils.checkNotNull(dataToDecrypt);
    Utils.checkNotNull(aesKey);

    try {
        ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(aesKey.getKey()), dataToDecrypt.getInitialisationVector());

        // Decrypt the message.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(false, keyWithIv);

        byte[] cipherBytes = dataToDecrypt.getEncryptedBytes();
        byte[] decryptedBytes = new byte[cipher.getOutputSize(cipherBytes.length)];
        final int length1 = cipher.processBytes(cipherBytes, 0, cipherBytes.length, decryptedBytes, 0);
        final int length2 = cipher.doFinal(decryptedBytes, length1);

        return Arrays.copyOf(decryptedBytes, length1 + length2);
    } catch (Exception e) {
        throw new NulsRuntimeException(e);
    }
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:30,代码来源:AESEncrypt.java

示例3: encrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * Password based encryption using AES - CBC 256 bits.
 */
@Override
public EncryptedData encrypt(byte[] plainBytes, KeyParameter key) {
    checkNotNull(plainBytes);
    checkNotNull(key);

    try {
        // Generate iv - each encryption call has a different iv.
        byte[] iv = new byte[BLOCK_LENGTH];
        secureRandom.nextBytes(iv);

        ParametersWithIV keyWithIv = new ParametersWithIV(key, iv);

        // Encrypt using AES.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(true, keyWithIv);
        byte[] encryptedBytes = new byte[cipher.getOutputSize(plainBytes.length)];
        final int length1 = cipher.processBytes(plainBytes, 0, plainBytes.length, encryptedBytes, 0);
        final int length2 = cipher.doFinal(encryptedBytes, length1);

        return new EncryptedData(iv, Arrays.copyOf(encryptedBytes, length1 + length2));
    } catch (Exception e) {
        throw new KeyCrypterException("Could not encrypt bytes.", e);
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:28,代码来源:KeyCrypterAes.java

示例4: decrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * Decrypt bytes previously encrypted with this class.
 *
 * @param dataToDecrypt    The data to decrypt
 * @param key              The AES key to use for decryption
 * @return                 The decrypted bytes
 * @throws                 KeyCrypterException if bytes could not be decrypted
 */
@Override
public byte[] decrypt(EncryptedData dataToDecrypt, KeyParameter key) {
    checkNotNull(dataToDecrypt);
    checkNotNull(key);

    try {
        ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(key.getKey()), dataToDecrypt.initialisationVector);

        // Decrypt the message.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(false, keyWithIv);

        byte[] cipherBytes = dataToDecrypt.encryptedBytes;
        byte[] decryptedBytes = new byte[cipher.getOutputSize(cipherBytes.length)];
        final int length1 = cipher.processBytes(cipherBytes, 0, cipherBytes.length, decryptedBytes, 0);
        final int length2 = cipher.doFinal(decryptedBytes, length1);

        return Arrays.copyOf(decryptedBytes, length1 + length2);
    } catch (Exception e) {
        throw new KeyCrypterException("Could not decrypt bytes", e);
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:31,代码来源:KeyCrypterAes.java

示例5: encrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * Password based encryption using AES - CBC 256 bits.
 */
@Override
public EncryptedData encrypt(byte[] plainBytes, KeyParameter aesKey) throws KeyCrypterException {
    checkNotNull(plainBytes);
    checkNotNull(aesKey);

    try {
        // Generate iv - each encryption call has a different iv.
        byte[] iv = new byte[BLOCK_LENGTH];
        secureRandom.nextBytes(iv);

        ParametersWithIV keyWithIv = new ParametersWithIV(aesKey, iv);

        // Encrypt using AES.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(true, keyWithIv);
        byte[] encryptedBytes = new byte[cipher.getOutputSize(plainBytes.length)];
        final int length1 = cipher.processBytes(plainBytes, 0, plainBytes.length, encryptedBytes, 0);
        final int length2 = cipher.doFinal(encryptedBytes, length1);

        return new EncryptedData(iv, Arrays.copyOf(encryptedBytes, length1 + length2));
    } catch (Exception e) {
        throw new KeyCrypterException("Could not encrypt bytes.", e);
    }
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:28,代码来源:KeyCrypterScrypt.java

示例6: decrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * Decrypt bytes previously encrypted with this class.
 *
 * @param dataToDecrypt    The data to decrypt
 * @param aesKey           The AES key to use for decryption
 * @return                 The decrypted bytes
 * @throws                 KeyCrypterException if bytes could not be decrypted
 */
@Override
public byte[] decrypt(EncryptedData dataToDecrypt, KeyParameter aesKey) throws KeyCrypterException {
    checkNotNull(dataToDecrypt);
    checkNotNull(aesKey);

    try {
        ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(aesKey.getKey()), dataToDecrypt.initialisationVector);

        // Decrypt the message.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(false, keyWithIv);

        byte[] cipherBytes = dataToDecrypt.encryptedBytes;
        byte[] decryptedBytes = new byte[cipher.getOutputSize(cipherBytes.length)];
        final int length1 = cipher.processBytes(cipherBytes, 0, cipherBytes.length, decryptedBytes, 0);
        final int length2 = cipher.doFinal(decryptedBytes, length1);

        return Arrays.copyOf(decryptedBytes, length1 + length2);
    } catch (Exception e) {
        throw new KeyCrypterException("Could not decrypt bytes", e);
    }
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:31,代码来源:KeyCrypterScrypt.java

示例7: decrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * Decrypt bytes previously encrypted with this class.
 *
 * @param privateKeyToDecode    The private key to decrypt
 * @param aesKey           The AES key to use for decryption
 * @return                 The decrypted bytes
 * @throws                 KeyCrypterException if bytes could not be decoded to a valid key
 */
@Override
public byte[] decrypt(EncryptedData privateKeyToDecode, KeyParameter aesKey) throws KeyCrypterException {
    checkNotNull(privateKeyToDecode);
    checkNotNull(aesKey);

    try {
        ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(aesKey.getKey()), privateKeyToDecode.initialisationVector);

        // Decrypt the message.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(false, keyWithIv);

        byte[] cipherBytes = privateKeyToDecode.encryptedBytes;
        byte[] decryptedBytes = new byte[cipher.getOutputSize(cipherBytes.length)];
        final int length1 = cipher.processBytes(cipherBytes, 0, cipherBytes.length, decryptedBytes, 0);
        final int length2 = cipher.doFinal(decryptedBytes, length1);

        return Arrays.copyOf(decryptedBytes, length1 + length2);
    } catch (Exception e) {
        throw new KeyCrypterException("Could not decrypt bytes", e);
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:31,代码来源:KeyCrypterScrypt.java

示例8: aesDecrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
public byte[] aesDecrypt(byte[] key, byte[] ctr, byte[] b) throws OtrCryptoException {

        AESFastEngine aesDec = new AESFastEngine();
        SICBlockCipher sicAesDec = new SICBlockCipher(aesDec);
        BufferedBlockCipher bufSicAesDec = new BufferedBlockCipher(sicAesDec);

        // Create initial counter value 0.
        if (ctr == null)
            ctr = ZERO_CTR;
        bufSicAesDec.init(false, new ParametersWithIV(new KeyParameter(key), ctr));
        byte[] aesOutLwDec = new byte[b.length];
        int done = bufSicAesDec.processBytes(b, 0, b.length, aesOutLwDec, 0);
        try {
            bufSicAesDec.doFinal(aesOutLwDec, done);
        } catch (Exception e) {
            throw new OtrCryptoException(e);
        }

        return aesOutLwDec;
    }
 
开发者ID:zom,项目名称:Zom-Android,代码行数:21,代码来源:OtrCryptoEngineImpl.java

示例9: aesEncrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
public byte[] aesEncrypt(byte[] key, byte[] ctr, byte[] b) throws OtrCryptoException {

        AESFastEngine aesEnc = new AESFastEngine();
        SICBlockCipher sicAesEnc = new SICBlockCipher(aesEnc);
        BufferedBlockCipher bufSicAesEnc = new BufferedBlockCipher(sicAesEnc);

        // Create initial counter value 0.
        if (ctr == null)
            ctr = ZERO_CTR;
        bufSicAesEnc.init(true, new ParametersWithIV(new KeyParameter(key), ctr));
        byte[] aesOutLwEnc = new byte[b.length];
        int done = bufSicAesEnc.processBytes(b, 0, b.length, aesOutLwEnc, 0);
        try {
            bufSicAesEnc.doFinal(aesOutLwEnc, done);
        } catch (Exception e) {
            throw new OtrCryptoException(e);
        }
        return aesOutLwEnc;
    }
 
开发者ID:zom,项目名称:Zom-Android,代码行数:20,代码来源:OtrCryptoEngineImpl.java

示例10: encrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * Password based encryption using AES - CBC 256 bits.
 */
@Override
public EncryptedPrivateKey encrypt(byte[] plainBytes, KeyParameter aesKey) throws KeyCrypterException {
    checkNotNull(plainBytes);
    checkNotNull(aesKey);

    try {
        // Generate iv - each encryption call has a different iv.
        byte[] iv = new byte[BLOCK_LENGTH];
        secureRandom.nextBytes(iv);

        ParametersWithIV keyWithIv = new ParametersWithIV(aesKey, iv);

        // Encrypt using AES.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(true, keyWithIv);
        byte[] encryptedBytes = new byte[cipher.getOutputSize(plainBytes.length)];
        final int length1 = cipher.processBytes(plainBytes, 0, plainBytes.length, encryptedBytes, 0);
        final int length2 = cipher.doFinal(encryptedBytes, length1);

        return new EncryptedPrivateKey(iv, Arrays.copyOf(encryptedBytes, length1 + length2));
    } catch (Exception e) {
        throw new KeyCrypterException("Could not encrypt bytes.", e);
    }
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:28,代码来源:KeyCrypterScrypt.java

示例11: decrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * Decrypt bytes previously encrypted with this class.
 *
 * @param privateKeyToDecode    The private key to decrypt
 * @param aesKey           The AES key to use for decryption
 * @return                 The decrypted bytes
 * @throws                 KeyCrypterException if bytes could not be decoded to a valid key
 */
@Override
public byte[] decrypt(EncryptedPrivateKey privateKeyToDecode, KeyParameter aesKey) throws KeyCrypterException {
    checkNotNull(privateKeyToDecode);
    checkNotNull(aesKey);

    try {
        ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(aesKey.getKey()), privateKeyToDecode.getInitialisationVector());

        // Decrypt the message.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(false, keyWithIv);

        byte[] cipherBytes = privateKeyToDecode.getEncryptedBytes();
        byte[] decryptedBytes = new byte[cipher.getOutputSize(cipherBytes.length)];
        final int length1 = cipher.processBytes(cipherBytes, 0, cipherBytes.length, decryptedBytes, 0);
        final int length2 = cipher.doFinal(decryptedBytes, length1);

        return Arrays.copyOf(decryptedBytes, length1 + length2);
    } catch (Exception e) {
        throw new KeyCrypterException("Could not decrypt bytes", e);
    }
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:31,代码来源:KeyCrypterScrypt.java

示例12: encrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * Password based encryption using AES - CBC 256 bits.
 * 
 * @param plainTextAsBytes
 *            The bytes to encrypt
 * @param password
 *            The password to use for encryption
 * @return SALT_LENGTH bytes of salt followed by the encrypted bytes.
 * @throws KeyCrypterException
 */
public byte[] encrypt(byte[] plainTextAsBytes, CharSequence password) throws KeyCrypterException {
    try {
        // Generate salt - each encryption call has a different salt.
        byte[] salt = new byte[SALT_LENGTH];
        secureRandom.nextBytes(salt);
 
        ParametersWithIV key = (ParametersWithIV) getAESPasswordKey(password, salt);

        // The following code uses an AES cipher to encrypt the message.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(true, key);
        byte[] encryptedBytes = new byte[cipher.getOutputSize(plainTextAsBytes.length)];
        final int processLength = cipher.processBytes(plainTextAsBytes, 0, plainTextAsBytes.length, encryptedBytes, 0);
        final int doFinalLength = cipher.doFinal(encryptedBytes, processLength);

        // The result bytes are the SALT_LENGTH bytes followed by the encrypted bytes.
        return concat(salt, Arrays.copyOf(encryptedBytes, processLength + doFinalLength));
    } catch (Exception e) {
        throw new KeyCrypterException("Could not encrypt bytes '" + Utils.bytesToHexString(plainTextAsBytes) + "'", e);
    }
}
 
开发者ID:coinspark,项目名称:sparkbit,代码行数:32,代码来源:KeyCrypterOpenSSL.java

示例13: decrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * Decrypt bytes previously encrypted with this class.
 * 
 * @param bytesToDecode
 *            The bytes to decrypt
 * @param password The password to use
 *            password to use for decryption
 * @return The decrypted bytes
 * @throws KeyCrypterException
 */
public byte[] decrypt(byte[] bytesToDecode, CharSequence password) throws KeyCrypterException {
    try {
        // separate the salt and bytes to decrypt
        byte[] salt = new byte[SALT_LENGTH];

        System.arraycopy(bytesToDecode, 0, salt, 0, SALT_LENGTH);

        byte[] cipherBytes = new byte[bytesToDecode.length - SALT_LENGTH];
        System.arraycopy(bytesToDecode, SALT_LENGTH, cipherBytes, 0, bytesToDecode.length - SALT_LENGTH);

        ParametersWithIV key = (ParametersWithIV) getAESPasswordKey(password, salt);

        // decrypt the message
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(false, key);

        byte[] decryptedBytes = new byte[cipher.getOutputSize(cipherBytes.length)];
        final int processLength = cipher.processBytes(cipherBytes, 0, cipherBytes.length, decryptedBytes, 0);
        final int doFinalLength = cipher.doFinal(decryptedBytes, processLength);

        return Arrays.copyOf(decryptedBytes, processLength + doFinalLength);
    } catch (Exception e) {
        throw new KeyCrypterException("Could not decrypt input string", e);
    }
}
 
开发者ID:coinspark,项目名称:sparkbit,代码行数:36,代码来源:KeyCrypterOpenSSL.java

示例14: decrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * Decrypt bytes previously encrypted with this class.
 *
 * @param privateKeyToDecode    The private key to decrypt
 * @param aesKey           The AES key to use for decryption
 * @return                 The decrypted bytes
 * @throws                 KeyCrypterException if bytes could not be decoded to a valid key
 */
@Override
public byte[] decrypt(EncryptedPrivateKey privateKeyToDecode, KeyParameter aesKey) throws KeyCrypterException {
    Preconditions.checkNotNull(privateKeyToDecode);
    Preconditions.checkNotNull(aesKey);

    try {
        ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(aesKey.getKey()), privateKeyToDecode.getInitialisationVector());

        // Decrypt the message.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(false, keyWithIv);

        byte[] cipherBytes = privateKeyToDecode.getEncryptedBytes();
        int minimumSize = cipher.getOutputSize(cipherBytes.length);
        byte[] outputBuffer = new byte[minimumSize];
        int length1 = cipher.processBytes(cipherBytes, 0, cipherBytes.length, outputBuffer, 0);
        int length2 = cipher.doFinal(outputBuffer, length1);
        int actualLength = length1 + length2;

        byte[] decryptedBytes = new byte[actualLength];
        System.arraycopy(outputBuffer, 0, decryptedBytes, 0, actualLength);

        return decryptedBytes;
    } catch (Exception e) {
        throw new KeyCrypterException("Could not decrypt bytes", e);
    }
}
 
开发者ID:appteam-nith,项目名称:NithPointsj,代码行数:36,代码来源:KeyCrypterScrypt.java

示例15: decrypt

import org.spongycastle.crypto.BufferedBlockCipher; //导入方法依赖的package包/类
/**
 * Decrypt bytes previously encrypted with this class.
 *
 * @param privateKeyToDecode The private key to decrypt
 * @param aesKey             The AES key to use for decryption
 * @return The decrypted bytes
 * @throws KeyCrypterException if bytes could not be decoded to a valid key
 */
@Override
public byte[] decrypt(EncryptedPrivateKey privateKeyToDecode, KeyParameter aesKey) throws KeyCrypterException {
    checkNotNull(privateKeyToDecode);
    checkNotNull(aesKey);

    try {
        ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(aesKey.getKey()), privateKeyToDecode.getInitialisationVector());

        // Decrypt the message.
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
        cipher.init(false, keyWithIv);

        byte[] cipherBytes = privateKeyToDecode.getEncryptedBytes();
        int minimumSize = cipher.getOutputSize(cipherBytes.length);
        byte[] outputBuffer = new byte[minimumSize];
        int length1 = cipher.processBytes(cipherBytes, 0, cipherBytes.length, outputBuffer, 0);
        int length2 = cipher.doFinal(outputBuffer, length1);
        int actualLength = length1 + length2;

        byte[] decryptedBytes = new byte[actualLength];
        System.arraycopy(outputBuffer, 0, decryptedBytes, 0, actualLength);

        wipeBytes(outputBuffer);

        return decryptedBytes;
    } catch (Exception e) {
        throw new KeyCrypterException("Could not decrypt bytes", e);
    }
}
 
开发者ID:chaincloud-dot-com,项目名称:chaincloud-v,代码行数:38,代码来源:KeyCrypterScrypt.java


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