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


Java AEADBlockCipher类代码示例

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


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

示例1: runTestCase

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
private void runTestCase(String testName, String[] testVector, int macLengthBits, byte[] K)
    throws InvalidCipherTextException
{
    int pos = 0;
    byte[] N = Hex.decode(testVector[pos++]);
    byte[] A = Hex.decode(testVector[pos++]);
    byte[] P = Hex.decode(testVector[pos++]);
    byte[] C = Hex.decode(testVector[pos++]);

    int macLengthBytes = macLengthBits / 8;

    KeyParameter keyParameter = new KeyParameter(K);
    AEADParameters parameters = new AEADParameters(keyParameter, macLengthBits, N, A);

    AEADBlockCipher encCipher = initOCBCipher(true, parameters);
    AEADBlockCipher decCipher = initOCBCipher(false, parameters);

    checkTestCase(encCipher, decCipher, testName, macLengthBytes, P, C);
    checkTestCase(encCipher, decCipher, testName + " (reused)", macLengthBytes, P, C);

    // Key reuse
    AEADParameters keyReuseParams = AEADTestUtil.reuseKey(parameters);
    encCipher.init(true, keyReuseParams);
    decCipher.init(false, keyReuseParams);
    checkTestCase(encCipher, decCipher, testName + " (key reuse)", macLengthBytes, P, C);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:27,代码来源:OCBTest.java

示例2: testReset

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
public static void testReset(Test test, AEADBlockCipher cipher1, AEADBlockCipher cipher2, CipherParameters params)
    throws InvalidCipherTextException
{
    cipher1.init(true, params);

    byte[] plaintext = new byte[1000];
    byte[] ciphertext = new byte[cipher1.getOutputSize(plaintext.length)];

    // Establish baseline answer
    crypt(cipher1, plaintext, ciphertext);

    // Test encryption resets
    checkReset(test, cipher1, params, true, plaintext, ciphertext);

    // Test decryption resets with fresh instance
    cipher2.init(false, params);
    checkReset(test, cipher2, params, false, ciphertext, plaintext);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:19,代码来源:AEADTestUtil.java

示例3: testMode

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
private void testMode(Object cipher, CipherParameters params)
    throws Exception
{
    testWriteRead(cipher, params, false);
    testWriteRead(cipher, params, true);
    testReadWrite(cipher, params, false);
    testReadWrite(cipher, params, true);

    if (!(cipher instanceof CTSBlockCipher || cipher instanceof NISTCTSBlockCipher))
    {
        testWriteReadEmpty(cipher, params, false);
        testWriteReadEmpty(cipher, params, true);
    }

    if (cipher instanceof AEADBlockCipher)
    {
        testTamperedRead((AEADBlockCipher)cipher, params);
        testTruncatedRead((AEADBlockCipher)cipher, params);
        testTamperedWrite((AEADBlockCipher)cipher, params);
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:22,代码来源:CipherStreamTest.java

示例4: createCipherInputStream

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
private InputStream createCipherInputStream(byte[] data, Object cipher)
{
    ByteArrayInputStream input = new ByteArrayInputStream(data);
    if (cipher instanceof BufferedBlockCipher)
    {
        return new CipherInputStream(input, (BufferedBlockCipher)cipher);
    }
    else if (cipher instanceof AEADBlockCipher)
    {
        return new CipherInputStream(input, (AEADBlockCipher)cipher);
    }
    else
    {
        return new CipherInputStream(input, (StreamCipher)cipher);
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:17,代码来源:CipherStreamTest.java

示例5: getName

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
private String getName(Object cipher)
{
    if (cipher instanceof BufferedBlockCipher)
    {
        return ((BufferedBlockCipher)cipher).getUnderlyingCipher().getAlgorithmName();
    }
    else if (cipher instanceof AEADBlockCipher)
    {
        return ((AEADBlockCipher)cipher).getUnderlyingCipher().getAlgorithmName();
    }
    else if (cipher instanceof StreamCipher)
    {
        return ((StreamCipher)cipher).getAlgorithmName();
    }
    return null;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:17,代码来源:CipherStreamTest.java

示例6: getBlockSize

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
private int getBlockSize(Object cipher)
{
    if (cipher instanceof BlockCipher)
    {
        return ((BlockCipher)cipher).getBlockSize();
    }
    else if (cipher instanceof BufferedBlockCipher)
    {
        return ((BufferedBlockCipher)cipher).getBlockSize();
    }
    else if (cipher instanceof AEADBlockCipher)
    {
        return ((AEADBlockCipher)cipher).getUnderlyingCipher().getBlockSize();
    }
    else if (cipher instanceof StreamCipher)
    {
        return 1;
    }
    return 0;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:21,代码来源:CipherStreamTest.java

示例7: transform

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
@Override
public void transform(InputStream in, OutputStream out) {
    try {
        AEADBlockCipher aeadBlockCipher = createAEADBlockCipher();

        AEADParameters aeadParameters = new AEADParameters(new KeyParameter(key.getKey()),
                Constants.GCM_MAC_SIZE, nonce, nonSecretPayload);

        aeadBlockCipher.init(true, aeadParameters);

        // Write nonce as first 4 bytes
        out.write(this.nonce);
        try (CipherInputStream cipherInputStream = new CipherInputStream(in, aeadBlockCipher)) {
            IOUtils.copy(cipherInputStream, out);
        }
    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);
        throw new EncryptorException(ex.getMessage(), ex);
    }
}
 
开发者ID:dzhemriza,项目名称:toffi,代码行数:21,代码来源:BaseBlockCipherEncoder.java

示例8: transform

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
@Override
public void transform(InputStream in, OutputStream out) {
    try {
        AEADBlockCipher aeadBlockCipher = createAEADBlockCipher();

        // Read the first 4 bytes as they contains nonce
        byte[] nonce = new byte[4];
        int bytesRead = in.read(nonce);
        if (bytesRead < 4) {
            throw new RuntimeException("Failed to read nonce! Bytes read=" + bytesRead);
        }

        AEADParameters aeadParameters = new AEADParameters(new KeyParameter(key.getKey()),
                Constants.GCM_MAC_SIZE, nonce, nonSecretPayload);

        aeadBlockCipher.init(false, aeadParameters);

        try (CipherOutputStream cipherOutputStream = new CipherOutputStream(out, aeadBlockCipher)) {
            IOUtils.copy(in, cipherOutputStream);
        }
    } catch (IOException ex) {
        LOG.error(ex.getMessage(), ex);
        throw new EncryptorException(ex.getMessage(), ex);
    }
}
 
开发者ID:dzhemriza,项目名称:toffi,代码行数:26,代码来源:BaseBlockCipherDecoder.java

示例9: CipherInputStream

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
/**
 * Constructs a CipherInputStream from an InputStream and an AEADBlockCipher.
 */
public CipherInputStream(
    InputStream is,
    AEADBlockCipher cipher)
{
    this(is, cipher, INPUT_BUF_SIZE);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:10,代码来源:CipherInputStream.java

示例10: updateCiphers

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
private int updateCiphers(AEADBlockCipher c1, AEADBlockCipher c2, byte[] S, int i,
    boolean includeAAD, boolean includePlaintext)
    throws InvalidCipherTextException
{
    int inputLen = includePlaintext ? i : 0;
    int outputLen = c2.getOutputSize(inputLen);

    byte[] output = new byte[outputLen];

    int len = 0;

    if (includeAAD)
    {
        c2.processAADBytes(S, 0, i);
    }

    if (includePlaintext)
    {
        len += c2.processBytes(S, 0, i, output, len);
    }

    len += c2.doFinal(output, len);

    c1.processAADBytes(output, 0, len);

    return len;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:28,代码来源:OCBTest.java

示例11: outputSizeTests

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
private void outputSizeTests()
{
    byte[] K = new byte[16];
    byte[] A = null;
    byte[] IV = new byte[15];

    AEADParameters parameters = new AEADParameters(new KeyParameter(K), 16 * 8, IV, A);
    AEADBlockCipher cipher = initOCBCipher(true, parameters);

    if (cipher.getUpdateOutputSize(0) != 0)
    {
        fail("incorrect getUpdateOutputSize for initial 0 bytes encryption");
    }

    if (cipher.getOutputSize(0) != 16)
    {
        fail("incorrect getOutputSize for initial 0 bytes encryption");
    }

    cipher.init(false, parameters);

    if (cipher.getUpdateOutputSize(0) != 0)
    {
        fail("incorrect getUpdateOutputSize for initial 0 bytes decryption");
    }

    // NOTE: 0 bytes would be truncated data, but we want it to fail in the doFinal, not here
    if (cipher.getOutputSize(0) != 0)
    {
        fail("fragile getOutputSize for initial 0 bytes decryption");
    }

    if (cipher.getOutputSize(16) != 0)
    {
        fail("incorrect getOutputSize for initial MAC-size bytes decryption");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:38,代码来源:OCBTest.java

示例12: createCipherOutputStream

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
private OutputStream createCipherOutputStream(OutputStream output, Object cipher)
{
    if (cipher instanceof BufferedBlockCipher)
    {
        return new CipherOutputStream(output, (BufferedBlockCipher)cipher);
    }
    else if (cipher instanceof AEADBlockCipher)
    {
        return new CipherOutputStream(output, (AEADBlockCipher)cipher);
    }
    else
    {
        return new CipherOutputStream(output, (StreamCipher)cipher);
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:16,代码来源:CipherStreamTest.java

示例13: testTamperedWrite

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
/**
 * Test tampering of ciphertext followed by write to decrypting CipherOutputStream
 */
private void testTamperedWrite(AEADBlockCipher cipher, CipherParameters params)
    throws Exception
{
    cipher.init(true, params);

    byte[] ciphertext = new byte[cipher.getOutputSize(streamSize)];
    cipher.doFinal(ciphertext, cipher.processBytes(new byte[streamSize], 0, streamSize, ciphertext, 0));

    // Tamper
    ciphertext[0] += 1;

    cipher.init(false, params);
    ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
    OutputStream output = createCipherOutputStream(plaintext, cipher);

    for (int i = 0; i < ciphertext.length; i++)
    {
        output.write(ciphertext[i]);
    }
    try
    {
        output.close();
        fail("Expected invalid ciphertext after tamper and write : " + cipher.getAlgorithmName());
    }
    catch (InvalidCipherTextIOException e)
    {
        // Expected
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:33,代码来源:CipherStreamTest.java

示例14: init

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
private void init(Object cipher, boolean forEncrypt, CipherParameters params)
{
    if (cipher instanceof BufferedBlockCipher)
    {
        ((BufferedBlockCipher)cipher).init(forEncrypt, params);
    }
    else if (cipher instanceof AEADBlockCipher)
    {
        ((AEADBlockCipher)cipher).init(forEncrypt, params);
    }
    else if (cipher instanceof StreamCipher)
    {
        ((StreamCipher)cipher).init(forEncrypt, params);
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:16,代码来源:CipherStreamTest.java

示例15: CipherInputStream

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
/**
 * Constructs a CipherInputStream from an InputStream and an AEADBlockCipher.
 */
public CipherInputStream(InputStream is, AEADBlockCipher cipher) {
    super(is);

    this.aeadBlockCipher = cipher;

    int outSize = cipher.getOutputSize(INPUT_BUF_SIZE);

    buf = new byte[(outSize > INPUT_BUF_SIZE) ? outSize : INPUT_BUF_SIZE];
    inBuf = new byte[INPUT_BUF_SIZE];
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:14,代码来源:CipherWriteStreamValidation.java


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