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

Java OCBBlockCipher类代码示例

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

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



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

示例1: testModes

import org.bouncycastle.crypto.modes.OCBBlockCipher; //导入依赖的package包/类
private void testModes(BlockCipher cipher1, BlockCipher cipher2, int keySize)
    throws Exception
{
    final KeyParameter key = new KeyParameter(new byte[keySize]);
    final int blockSize = getBlockSize(cipher1);
    final CipherParameters withIv = new ParametersWithIV(key, new byte[blockSize]);

    if (blockSize > 1)
    {
        testMode(new PaddedBufferedBlockCipher(cipher1, new PKCS7Padding()), key);

        testMode(new PaddedBufferedBlockCipher(new CBCBlockCipher(cipher1), new PKCS7Padding()), withIv);

        testMode(new BufferedBlockCipher(new OFBBlockCipher(cipher1, blockSize)), withIv);
        testMode(new BufferedBlockCipher(new CFBBlockCipher(cipher1, blockSize)), withIv);
        testMode(new BufferedBlockCipher(new SICBlockCipher(cipher1)), withIv);
    }
    // CTS requires at least one block
    if (blockSize <= 16 && streamSize >= blockSize)
    {
        testMode(new CTSBlockCipher(cipher1), key);
    }
    if (blockSize <= 16 && streamSize >= blockSize)
    {
        testMode(new NISTCTSBlockCipher(NISTCTSBlockCipher.CS1, cipher1), key);
        testMode(new NISTCTSBlockCipher(NISTCTSBlockCipher.CS2, cipher1), key);
        testMode(new NISTCTSBlockCipher(NISTCTSBlockCipher.CS3, cipher1), key);
    }
    if (blockSize == 8 || blockSize == 16)
    {
        testMode(new EAXBlockCipher(cipher1), withIv);
    }
    if (blockSize == 16)
    {
        testMode(new CCMBlockCipher(cipher1), new ParametersWithIV(key, new byte[7]));
        testMode(new GCMBlockCipher(cipher1), withIv);
        testMode(new OCBBlockCipher(cipher1, cipher2), new ParametersWithIV(key, new byte[15]));
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:40,代码来源:CipherStreamTest.java


示例2: runTestCase

import org.bouncycastle.crypto.modes.OCBBlockCipher; //导入依赖的package包/类
private void runTestCase(String testName, String[] testVector, int macLengthBits)
    throws InvalidCipherTextException
{

    byte[] key = Hex.decode(K);
    byte[] nonce = Hex.decode(N);

    int pos = 0;
    byte[] A = Hex.decode(testVector[pos++]);
    byte[] P = Hex.decode(testVector[pos++]);
    byte[] C = Hex.decode(testVector[pos++]);

    int macLengthBytes = macLengthBits / 8;

    // TODO Variations processing AAD and cipher bytes incrementally

    KeyParameter keyParameter = new KeyParameter(key);
    AEADParameters aeadParameters = new AEADParameters(keyParameter, macLengthBits, nonce, A);

    OCBBlockCipher encCipher = initCipher(true, aeadParameters);
    OCBBlockCipher decCipher = initCipher(false, aeadParameters);

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

    // TODO Key reuse
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:28,代码来源:OCBTest.java


示例3: createOCBCipher

import org.bouncycastle.crypto.modes.OCBBlockCipher; //导入依赖的package包/类
private AEADBlockCipher createOCBCipher()
{
    return new OCBBlockCipher(createUnderlyingCipher(), createUnderlyingCipher());
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:5,代码来源:OCBTest.java


示例4: createOCBCipher

import org.bouncycastle.crypto.modes.OCBBlockCipher; //导入依赖的package包/类
private static AEADBlockCipher createOCBCipher(boolean forEncryption, AEADParameters parameters) {
    AEADBlockCipher c = new OCBBlockCipher(new AESEngine(), new AESEngine());
    c.init(forEncryption, parameters);

    return c;
}
 
开发者ID:nelenkov,项目名称:keystore-decryptor,代码行数:7,代码来源:Keymaster1Blob.java


示例5: initCipher

import org.bouncycastle.crypto.modes.OCBBlockCipher; //导入依赖的package包/类
private OCBBlockCipher initCipher(boolean forEncryption, AEADParameters parameters)
{
    OCBBlockCipher c = new OCBBlockCipher(new AESFastEngine(), new AESFastEngine());
    c.init(forEncryption, parameters);
    return c;
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:7,代码来源:OCBTest.java


示例6: runLongerTestCase

import org.bouncycastle.crypto.modes.OCBBlockCipher; //导入依赖的package包/类
private void runLongerTestCase(int aesKeySize, int tagLen, byte[] expectedOutput)
    throws InvalidCipherTextException
{
    KeyParameter key = new KeyParameter(new byte[aesKeySize / 8]);
    byte[] N = new byte[12];

    AEADBlockCipher c1 = new OCBBlockCipher(new AESFastEngine(), new AESFastEngine());
    c1.init(true, new AEADParameters(key, tagLen, N));

    AEADBlockCipher c2 = new OCBBlockCipher(new AESFastEngine(), new AESFastEngine());

    long total = 0;

    byte[] S = new byte[128];

    for (int i = 0; i < 128; ++i)
    {
        N[11] = (byte)i;

        c2.init(true, new AEADParameters(key, tagLen, N));

        total += updateCiphers(c1, c2, S, i, true, true);
        total += updateCiphers(c1, c2, S, i, false, true);
        total += updateCiphers(c1, c2, S, i, true, false);
    }

    long expectedTotal = 16256 + (48 * tagLen);

    if (total != expectedTotal)
    {
        fail("test generated the wrong amount of input: " + total);
    }

    byte[] output = new byte[c1.getOutputSize(0)];
    c1.doFinal(output, 0);

    if (!areEqual(expectedOutput, output))
    {
        fail("incorrect encrypt in long-form test");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:42,代码来源:OCBTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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