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


Java AESFastEngine类代码示例

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


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

示例1: CipherWriteStreamValidation

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
public CipherWriteStreamValidation(byte[] secretBytes, byte[] salt) {
    this.salt = salt.clone();
    secretBytes = secretBytes.clone();
    if (secretBytes.length != KEY_SIZE_BYTES) {
        secretBytes = Hashing.sha256().hashBytes(secretBytes).asBytes();
    }
    try {
        KeyParameter key = new KeyParameter(secretBytes);
        AEADParameters params = new AEADParameters(key, MAC_SIZE_BITS, this.salt);

        this.encryptor = new GCMBlockCipher(new AESFastEngine());
        this.encryptor.init(true, params);

        this.decryptor = new GCMBlockCipher(new AESFastEngine());
        this.decryptor.init(false, params);

    } catch (Exception e) {
        throw new RuntimeException("could not create cipher for AES256", e);
    } finally {
        Arrays.fill(secretBytes, (byte) 0);
    }
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:23,代码来源:CipherWriteStreamValidation.java

示例2: getCipher

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
@Override
protected StreamCipher getCipher() {
    String method = getMethod();
    AESFastEngine engine = new AESFastEngine();

    switch (method) {
        case CIPHER_AES_128_CFB:
        case CIPHER_AES_192_CFB:
        case CIPHER_AES_256_CFB:
            return new CFBBlockCipher(engine, 128);
        case CIPHER_AES_128_CFB8:
        case CIPHER_AES_192_CFB8:
        case CIPHER_AES_256_CFB8:
            return new CFBBlockCipher(engine, 8);
        case CIPHER_AES_128_OFB:
        case CIPHER_AES_192_OFB:
        case CIPHER_AES_256_OFB:
            return new OFBBlockCipher(engine, 128);
        default:
            throw new IllegalArgumentException(method);
    }
}
 
开发者ID:zhoulifu,项目名称:ss-java,代码行数:23,代码来源:AesCrypto.java

示例3: encryptOrDecrypt

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
private byte[] encryptOrDecrypt(byte[] key, byte[] contents, boolean forEncryption) {

        // Credstash uses standard AES
        BlockCipher engine = new AESFastEngine();

        // Credstash uses CTR mode
        StreamBlockCipher cipher = new SICBlockCipher(engine);

        cipher.init(forEncryption, new ParametersWithIV(new KeyParameter(key), INITIALIZATION_VECTOR));

        byte[] resultBytes = new byte[contents.length];
        int contentsOffset = 0;
        int resultOffset = 0;
        cipher.processBytes(contents, contentsOffset, contents.length, resultBytes, resultOffset);
        return resultBytes;
    }
 
开发者ID:jessecoyle,项目名称:jcredstash,代码行数:17,代码来源:CredStashBouncyCastleCrypto.java

示例4: createWrapper

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
static Wrapper createWrapper(int encAlgorithm)
    throws PGPException
{
    switch (encAlgorithm)
    {
    case SymmetricKeyAlgorithmTags.AES_128:
    case SymmetricKeyAlgorithmTags.AES_192:
    case SymmetricKeyAlgorithmTags.AES_256:
        return new RFC3394WrapEngine(new AESFastEngine());
    case SymmetricKeyAlgorithmTags.CAMELLIA_128:
    case SymmetricKeyAlgorithmTags.CAMELLIA_192:
    case SymmetricKeyAlgorithmTags.CAMELLIA_256:
        return new RFC3394WrapEngine(new CamelliaEngine());
    default:
        throw new PGPException("unknown wrap algorithm: " + encAlgorithm);
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:18,代码来源:BcImplProvider.java

示例5: performTest

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
public void performTest()
{
    for (int i = 0; i < TEST_VECTORS.length; i++)
    {
        TestCase testCase = TEST_VECTORS[i];

        Mac mac = new GMac(new GCMBlockCipher(new AESFastEngine()), testCase.getTag().length * 8);
        CipherParameters key = new KeyParameter(testCase.getKey());
        mac.init(new ParametersWithIV(key, testCase.getIv()));

        testSingleByte(mac, testCase);
        testMultibyte(mac, testCase);
    }

    // Invalid mac size
    testInvalidMacSize(97);
    testInvalidMacSize(136);
    testInvalidMacSize(24);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:20,代码来源:GMacTest.java

示例6: testInvalidMacSize

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
private void testInvalidMacSize(int size)
{
    try
    {
        GMac mac = new GMac(new GCMBlockCipher(new AESFastEngine()), size);
        mac.init(new ParametersWithIV(null, new byte[16]));
        fail("Expected failure for illegal mac size " + size);
    }
    catch (IllegalArgumentException e)
    {
        if (!e.getMessage().startsWith("Invalid value for MAC size"))
        {
            fail("Illegal mac size failed with unexpected message");
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:17,代码来源:GMacTest.java

示例7: SAES256v01

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
public SAES256v01(byte[] secretBytes, byte[] salt) {
    this.salt = salt.clone();
    secretBytes = secretBytes.clone();
    if (secretBytes.length != KEY_SIZE_BYTES) {
        secretBytes = Hashing.sha256().hashBytes(secretBytes).asBytes();
    }
    try {
        KeyParameter key = new KeyParameter(secretBytes);
        AEADParameters params = new AEADParameters(key, MAC_SIZE_BITS, this.salt);

        this.encryptor = new GCMBlockCipher(new AESFastEngine());
        this.encryptor.init(true, params);

        this.decryptor = new GCMBlockCipher(new AESFastEngine());
        this.decryptor.init(false, params);

    } catch (Exception e) {
        throw new RuntimeException("could not create cipher for AES256", e);
    } finally {
        Arrays.fill(secretBytes, (byte) 0);
    }
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:23,代码来源:SAES256v01.java

示例8: initCiphers

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
private void initCiphers(byte[] key, byte[] iv) {

		// get the keyBytes
		keyBytes = new byte[key.length];
		System.arraycopy(key, 0, keyBytes, 0, key.length);

		keyP = new KeyParameter(keyBytes);

		// get the IV
		IV = new byte[blockSize];
		System.arraycopy(iv, 0, IV, 0, IV.length);

		// create the ciphers
		// AES block cipher in CBC mode with ISO7816d4 padding
		encryptCipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(
				new AESFastEngine()), new ISO7816d4Padding());

		decryptCipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(
				new AESFastEngine()), new ISO7816d4Padding());

		// create the IV parameter
		ParametersWithIV parameterIV = new ParametersWithIV(keyP, IV);

		encryptCipher.init(true, parameterIV);
		decryptCipher.init(false, parameterIV);
	}
 
开发者ID:tsenger,项目名称:animamea,代码行数:27,代码来源:AmAESCrypto.java

示例9: getMAC

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
@Override
public byte[] getMAC(byte[] data) {

	byte[] n = new byte[sscBytes.length + data.length];
	System.arraycopy(sscBytes, 0, n, 0, sscBytes.length);
	System.arraycopy(data, 0, n, sscBytes.length, data.length);
	n = addPadding(n);

	BlockCipher cipher = new AESFastEngine();
	Mac mac = new CMac(cipher, 64);

	mac.init(keyP);
	mac.update(n, 0, n.length);
	byte[] out = new byte[mac.getMacSize()];

	mac.doFinal(out, 0);

	return out;
}
 
开发者ID:tsenger,项目名称:animamea,代码行数:20,代码来源:AmAESCrypto.java

示例10: genKeyId

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的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

示例11: decrypt

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的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

示例12: decrypt

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的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

示例13: decryptAESCBC

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
public static byte[] decryptAESCBC(byte[] key, byte[] iv, byte[] data) {
    // AES CBC PKCS7 decrypt
    try {
        CipherParameters cipherParameters = new ParametersWithIV(new KeyParameter(key), iv);
        PaddedBufferedBlockCipher cipher
                = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()), new PKCS7Padding());
        cipher.init(false, cipherParameters);

        byte[] buffer = new byte[cipher.getOutputSize(data.length)];

        int pos = cipher.processBytes(data, 0, data.length, buffer, 0);
        pos += cipher.doFinal(buffer, pos);

        return Arrays.copyOf(buffer, pos);

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

示例14: decryptDataAES256

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
/**
 * Encrypt or decrypt data with AES256.
 *
 * @param data The data to encrypt.
 * @param output The output to write the encrypted data to.
 *
 * @throws IOException If there is an error reading the data.
 */
private void decryptDataAES256(InputStream data, OutputStream output) throws IOException
{
    byte[] iv = new byte[16];

    // read IV from stream
    int ivSize = data.read(iv);
    if (ivSize == -1)
    {
        return;
    }

    if (ivSize != iv.length)
    {
        throw new IOException("AES initialization vector not fully read: only " + ivSize
                + " bytes read instead of " + iv.length);
    }
    PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(
            new CBCBlockCipher(new AESFastEngine()));
    cipher.init(false, new ParametersWithIV(new KeyParameter(encryptionKey), iv));
    try (CipherInputStream cis = new CipherInputStream(data, cipher))
    {
        org.apache.commons.io.IOUtils.copy(cis, output);
    }
}
 
开发者ID:torakiki,项目名称:sambox,代码行数:33,代码来源:SecurityHandler.java

示例15: main

import org.bouncycastle.crypto.engines.AESFastEngine; //导入依赖的package包/类
public static void main(String[] args)
        throws InterruptedException, IOException
    {
//        testTF_1024_1();
//        testTF_1024_2();
        testTF_512_1();
        testTF_512_2();
//        testTF_256_1();
//        testTF_256_2();
        System.out.println("Initialising test data.");
        byte[] input = new byte[DATA_SIZE];
        rand.nextBytes(input);

        System.out.println("Init complete.");
//        speedTestCipher(new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256), input);
        speedTestCipher(new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), input);
//        speedTestCipher(new Skein3FishEngine(), input);
//        speedTestCipher(new ThreefishEngine(ThreefishEngine.BLOCKSIZE_1024), input);
//        speedTestCipher(new ThreefishReferenceEngine(), input);
        speedTestCipher(new AESFastEngine(), input);
//        speedTestCipher(new TwofishEngine(), input);
//        speedTestCipher(new BlowfishEngine(), input);
    }
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:24,代码来源:ThroughputTest.java


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