• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AEADBlockCipher类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: BaseBlockCipher

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
protected BaseBlockCipher(
    AEADBlockCipher engine)
{
    baseEngine = engine.getUnderlyingCipher();
    ivLength = baseEngine.getBlockSize();
    cipher = new AEADGenericBlockCipher(engine);
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:8,代码来源:BaseBlockCipher.java


示例17: createAEADBlockCipherMode

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
private AEADBlockCipher createAEADBlockCipherMode(final String modeName, final BlockCipher engine)
{
	final Class<? extends AEADBlockCipher> modeClass = modeName2aeadBlockCipherModeClass.get(modeName);
	if (modeClass == null)
		return null;

	try {
		final Constructor<? extends AEADBlockCipher> c = modeClass.getConstructor(BlockCipher.class);
		return c.newInstance(engine);
	} catch (final Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:subshare,项目名称:subshare,代码行数:14,代码来源:CryptoRegistry.java


示例18: createCipherForBlockCipherMode

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
private Cipher createCipherForBlockCipherMode(final String transformation, final AEADBlockCipher modeWithEngine, final String engineName, final String modeName, final String paddingName)
throws NoSuchPaddingException
{
	if (paddingName.isEmpty() || "NOPADDING".equals(paddingName))
		return new AEADBlockCipherImpl(transformation, modeWithEngine);

	throw new NoSuchPaddingException("The AEAD-mode \"" + modeName + "\" does not support the padding \"" + paddingName + "\"! Padding must be \"NoPadding\" or an empty string!");
}
 
开发者ID:subshare,项目名称:subshare,代码行数:9,代码来源:CryptoRegistry.java


示例19: setupInputStream

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
public static InputStream setupInputStream(InputStream is, byte[] keyAndIv) {
    if (keyAndIv != null && keyAndIv.length == 48) {
        byte[] key = new byte[32];
        byte[] iv = new byte[16];
        System.arraycopy(keyAndIv, 0, iv, 0, 16);
        System.arraycopy(keyAndIv, 16, key, 0, 32);
        AEADBlockCipher cipher = new GCMBlockCipher(new AESEngine());
        cipher.init(true, new AEADParameters(new KeyParameter(key), 128, iv));
        return new CipherInputStream(is, cipher);
    } else {
        return is;
    }
}
 
开发者ID:zom,项目名称:Zom-Android,代码行数:14,代码来源:Downloader.java


示例20: setupOutputStream

import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
public static OutputStream setupOutputStream(OutputStream os, String reference) {
    if (reference != null && reference.length() == 96) {
        byte[] keyAndIv = hexToBytes(reference);
        byte[] key = new byte[32];
        byte[] iv = new byte[16];
        System.arraycopy(keyAndIv, 0, iv, 0, 16);
        System.arraycopy(keyAndIv, 16, key, 0, 32);
        AEADBlockCipher cipher = new GCMBlockCipher(new AESEngine());
        cipher.init(false, new AEADParameters(new KeyParameter(key), 128, iv));
        return new CipherOutputStream(os, cipher);
    } else {
        return os;
    }
}
 
开发者ID:zom,项目名称:Zom-Android,代码行数:15,代码来源:Downloader.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ThrowsException类代码示例发布时间:2022-05-21
下一篇:
Java FacetTypeRegistry类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap