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


Java GCMBlockCipher.doFinal方法代码示例

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


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

示例1: genKeyId

import org.bouncycastle.crypto.modes.GCMBlockCipher; //导入方法依赖的package包/类
private AesKeyId genKeyId() {
    try {
        final GCMBlockCipher gcm = new GCMBlockCipher(new AESFastEngine());
        gcm.init(true, new AEADParameters(
            new KeyParameter(key), 128, KEYID_AD, KEYID_AD));
        final byte[] ciphertext = new byte[gcm.getOutputSize(ZERO_BYTES.length)];
        final int resp = gcm.processBytes(ZERO_BYTES, 0, ZERO_BYTES.length,
            ciphertext, 0);
        gcm.doFinal(ciphertext, resp);
        return new AesKeyId(ciphertext);
    } catch (final InvalidCipherTextException e) {
        // Should be impossible when we're encrypting!
        throw new RuntimeException(
            "Unexpected behaviour in crypto libraries", e);
    }
}
 
开发者ID:lshift,项目名称:bletchley,代码行数:17,代码来源:AesKey.java

示例2: decrypt

import org.bouncycastle.crypto.modes.GCMBlockCipher; //导入方法依赖的package包/类
public SequenceItem decrypt(final ConverterCatalog r, final AesPacket packet)
    throws InvalidInputException {
    final GCMBlockCipher gcm = new GCMBlockCipher(new AESFastEngine());
    gcm.init(false, new AEADParameters(
        new KeyParameter(key), 128, packet.nonce, ZERO_BYTES));
    final byte[] newtext = new byte[
        gcm.getOutputSize(packet.ciphertext.length)];
    final int pp = gcm.processBytes(packet.ciphertext, 0,
        packet.ciphertext.length, newtext, 0);
    try {
        gcm.doFinal(newtext, pp);
    } catch (final InvalidCipherTextException e) {
        throw new CryptographyException(e);
    }
    return ConvertUtils.fromBytes(r, SequenceItem.class, newtext);
}
 
开发者ID:lshift,项目名称:bletchley,代码行数:17,代码来源:AesKey.java

示例3: decrypt

import org.bouncycastle.crypto.modes.GCMBlockCipher; //导入方法依赖的package包/类
public static byte[] decrypt(byte[] key, byte[] data) {
    // TODO utilize GCMAES#decrypt method
    try {
        if (data.length < NONCE_LENGTH + TAG_LENGTH) {
            throw new IllegalArgumentException("data packet too short");
        }

        int cipherTextLength = data.length - NONCE_LENGTH - TAG_LENGTH;

        byte[] nonce = Arrays.copyOf(data, NONCE_LENGTH);

        GCMBlockCipher cipher = new GCMBlockCipher(new AESFastEngine());
        AEADParameters parameters = new AEADParameters(new KeyParameter(key), TAG_LENGTH * 8, nonce);
        cipher.init(false, parameters);

        byte[] out = new byte[cipher.getOutputSize(cipherTextLength + TAG_LENGTH)];

        int pos = cipher.processBytes(data, NONCE_LENGTH, data.length - NONCE_LENGTH, out, 0);
        pos += cipher.doFinal(out, pos);

        return Arrays.copyOf(out, pos);

    } catch (IllegalStateException | InvalidCipherTextException ex) {
        throw new IllegalArgumentException(ex);
    }
}
 
开发者ID:horrorho,项目名称:InflatableDonkey,代码行数:27,代码来源:GCMDataB.java

示例4: aesGcmEncrypt

import org.bouncycastle.crypto.modes.GCMBlockCipher; //导入方法依赖的package包/类
public static byte[] aesGcmEncrypt(Transformation transformation, byte[] raw, byte[] secret, int atLength, byte[] iv, byte[] aad) throws Exception {
	BlockCipher blockCipher = new AESEngine();
	blockCipher.init(true, new KeyParameter(new SecretKeySpec(secret, "AES").getEncoded()));

	GCMBlockCipher aGCMBlockCipher = new GCMBlockCipher(blockCipher);
	aGCMBlockCipher.init(true, new AEADParameters(new KeyParameter(secret), atLength, iv, aad));

	int len = aGCMBlockCipher.getOutputSize(raw.length);
	byte[] out = new byte[len];
	int outOff = aGCMBlockCipher.processBytes(raw, 0, raw.length, out, 0);
	aGCMBlockCipher.doFinal(out, outOff);

	return out;
}
 
开发者ID:SKplanet,项目名称:syruppay-java,代码行数:15,代码来源:CryptoUtils.java

示例5: encrypt

import org.bouncycastle.crypto.modes.GCMBlockCipher; //导入方法依赖的package包/类
public AesPacket encrypt(final SequenceItem message) {
        final byte[] nonce = Ec.randomBytes(12);
        final GCMBlockCipher gcm = new GCMBlockCipher(new AESFastEngine());
        gcm.init(true, new AEADParameters(
            new KeyParameter(key), 128, nonce, ZERO_BYTES));
        final byte[] plaintext =
            ConvertUtils.toBytes(message);
        final byte[] ciphertext = new byte[gcm.getOutputSize(plaintext.length)];
        final int resp = gcm.processBytes(plaintext, 0, plaintext.length,
            ciphertext, 0);
        try {
            gcm.doFinal(ciphertext, resp);
        } catch (final InvalidCipherTextException e) {
            // Should be impossible when we're encrypting!
            throw new RuntimeException(
                "Unexpected behaviour in crypto libraries", e);
        }
        return new AesPacket(getKeyId(), nonce, ciphertext);
}
 
开发者ID:lshift,项目名称:bletchley,代码行数:20,代码来源:AesKey.java

示例6: decrypt

import org.bouncycastle.crypto.modes.GCMBlockCipher; //导入方法依赖的package包/类
/**
 * Returns decrypted data.
 *
 * @param key
 * @param nonce nonce/ IV
 * @param header
 * @param encryptedData
 * @param tag
 * @param optional optional AADBytes (post header)
 * @return decrypted data
 * @throws IllegalArgumentException on decryption exceptions
 * @throws NullPointerException on null arguments
 */
public static byte[] decrypt(
        byte[] key,
        byte[] nonce,
        byte[] header,
        byte[] encryptedData,
        byte[] tag,
        Optional<byte[]> optional) {

    try {
        GCMBlockCipher cipher = new GCMBlockCipher(new AESFastEngine());
        AEADParameters parameters = new AEADParameters(new KeyParameter(key), tag.length * 8, nonce, header);
        cipher.init(false, parameters);

        if (optional.isPresent()) {
            byte[] aadBytes = optional.get();
            cipher.processAADBytes(aadBytes, 0, aadBytes.length);
        }

        byte[] out = new byte[cipher.getOutputSize(encryptedData.length + tag.length)];

        int pos = cipher.processBytes(encryptedData, 0, encryptedData.length, out, 0);
        pos += cipher.processBytes(tag, 0, tag.length, out, pos);
        pos += cipher.doFinal(out, pos);

        return Arrays.copyOf(out, pos);

    } catch (IllegalStateException | InvalidCipherTextException | RuntimeCryptoException ex) {
        throw new IllegalStateException("GCM decrypt error", ex);
    }
}
 
开发者ID:horrorho,项目名称:InflatableDonkey,代码行数:44,代码来源:AESGCM.java

示例7: aesGcmDecrypt

import org.bouncycastle.crypto.modes.GCMBlockCipher; //导入方法依赖的package包/类
public static byte[] aesGcmDecrypt(Transformation transformation, byte[] encryptedData, byte[] secret, int atLength, byte[] iv, byte[] aad) throws Exception {
	BlockCipher blockCipher = new AESEngine();
	blockCipher.init(false, new KeyParameter(new SecretKeySpec(secret, "AES").getEncoded()));

	GCMBlockCipher aGCMBlockCipher = new GCMBlockCipher(blockCipher);
	aGCMBlockCipher.init(false, new AEADParameters(new KeyParameter(secret), atLength, iv, aad));

	int len = aGCMBlockCipher.getOutputSize(encryptedData.length);
	byte[] out = new byte[len];
	int outOff = aGCMBlockCipher.processBytes(encryptedData, 0, encryptedData.length, out, 0);
	aGCMBlockCipher.doFinal(out, outOff);

	return out;
}
 
开发者ID:SKplanet,项目名称:syruppay-java,代码行数:15,代码来源:CryptoUtils.java

示例8: checkTestCase

import org.bouncycastle.crypto.modes.GCMBlockCipher; //导入方法依赖的package包/类
private void checkTestCase(
        GCMBlockCipher  encCipher,
        GCMBlockCipher  decCipher,
        String          testName,
        byte[]          SA,
        byte[]          P,
        byte[]          C,
        byte[]          T)
        throws InvalidCipherTextException
    {
        byte[] enc = new byte[encCipher.getOutputSize(P.length)];
        if (SA != null)
        {
            encCipher.processAADBytes(SA, 0, SA.length);
        }
        int len = encCipher.processBytes(P, 0, P.length, enc, 0);
        len += encCipher.doFinal(enc, len);

        if (enc.length != len)
        {
//            System.out.println("" + enc.length + "/" + len);
            fail("encryption reported incorrect length: " + testName);
        }

        byte[] mac = encCipher.getMac();

        byte[] data = new byte[P.length];
        System.arraycopy(enc, 0, data, 0, data.length);
        byte[] tail = new byte[enc.length - P.length];
        System.arraycopy(enc, P.length, tail, 0, tail.length);

        if (!areEqual(C, data))
        {
            fail("incorrect encrypt in: " + testName);
        }

        if (!areEqual(T, mac))
        {
            fail("getMac() returned wrong mac in: " + testName);
        }

        if (!areEqual(T, tail))
        {
            fail("stream contained wrong mac in: " + testName);
        }

        byte[] dec = new byte[decCipher.getOutputSize(enc.length)];
        if (SA != null)
        {
            decCipher.processAADBytes(SA, 0, SA.length);
        }
        len = decCipher.processBytes(enc, 0, enc.length, dec, 0);
        len += decCipher.doFinal(dec, len);
        mac = decCipher.getMac();

        data = new byte[C.length];
        System.arraycopy(dec, 0, data, 0, data.length);

        if (!areEqual(P, data))
        {
            fail("incorrect decrypt in: " + testName);
        }
    }
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:64,代码来源:GCMTest.java


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