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


Java TweakableBlockCipherParameters类代码示例

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


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

示例1: init

import org.bouncycastle.crypto.params.TweakableBlockCipherParameters; //导入依赖的package包/类
public void init(boolean forEncryption, CipherParameters params)
    throws IllegalArgumentException
{
    if (params instanceof TweakableBlockCipherParameters)
    {
        init(forEncryption, (TweakableBlockCipherParameters)params);
    }
    else if (params instanceof KeyParameter)
    {
        init(forEncryption, new TweakableBlockCipherParameters((KeyParameter)params, new byte[TWEAK_SIZE]));
    }
    else
    {
        throw new IllegalArgumentException("Invalid parameter passed to Threefish init - "
            + params.getClass().getName());
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:18,代码来源:ThreefishReferenceEngine.java

示例2: runTestVector

import org.bouncycastle.crypto.params.TweakableBlockCipherParameters; //导入依赖的package包/类
private static void runTestVector(String name, byte[] key, byte[] tweak, byte[] plaintext, byte[] expected, BlockCipher cipher)
{
    System.out.println("====");
    System.out.println(name + ": ");
    cipher.init(true, new TweakableBlockCipherParameters(new KeyParameter(key), tweak));

    byte[] ciphertext = new byte[key.length];
    cipher.processBlock(plaintext, 0, ciphertext, 0);

    System.out.println("Plaintext  : " + new String(Hex.encode(plaintext)));
    System.out.println("Expected   : " + new String(Hex.encode(expected)));
    System.out.println("Ciphertext : " + new String(Hex.encode(ciphertext)));
    System.out.println("  Encrypt  : " + org.bouncycastle.util.Arrays.areEqual(expected, ciphertext));

    cipher.init(false, new TweakableBlockCipherParameters(new KeyParameter(key), tweak));
    byte[] replain = new byte[plaintext.length];
    cipher.processBlock(ciphertext, 0, replain, 0);

    System.out.println("Replain    : " + new String(Hex.encode(replain)));
    System.out.println("  Decrypt  : " + org.bouncycastle.util.Arrays.areEqual(plaintext, replain));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:22,代码来源:ThroughputTest.java

示例3: init

import org.bouncycastle.crypto.params.TweakableBlockCipherParameters; //导入依赖的package包/类
/**
 * Initialise the engine.
 *
 * @param params an instance of {@link TweakableBlockCipherParameters}, or {@link KeyParameter} (to
 *               use a 0 tweak)
 */
public void init(boolean forEncryption, CipherParameters params)
    throws IllegalArgumentException
{
    final byte[] keyBytes;
    final byte[] tweakBytes;

    if (params instanceof TweakableBlockCipherParameters)
    {
        TweakableBlockCipherParameters tParams = (TweakableBlockCipherParameters)params;
        keyBytes = tParams.getKey().getKey();
        tweakBytes = tParams.getTweak();
    }
    else if (params instanceof KeyParameter)
    {
        keyBytes = ((KeyParameter)params).getKey();
        tweakBytes = null;
    }
    else
    {
        throw new IllegalArgumentException("Invalid parameter passed to Threefish init - "
            + params.getClass().getName());
    }

    long[] keyWords = null;
    long[] tweakWords = null;

    if (keyBytes != null)
    {
        if (keyBytes.length != this.blocksizeBytes)
        {
            throw new IllegalArgumentException("Threefish key must be same size as block (" + blocksizeBytes
                + " bytes)");
        }
        keyWords = new long[blocksizeWords];
        for (int i = 0; i < keyWords.length; i++)
        {
            keyWords[i] = bytesToWord(keyBytes, i * 8);
        }
    }
    if (tweakBytes != null)
    {
        if (tweakBytes.length != TWEAK_SIZE_BYTES)
        {
            throw new IllegalArgumentException("Threefish tweak must be " + TWEAK_SIZE_BYTES + " bytes");
        }
        tweakWords = new long[]{bytesToWord(tweakBytes, 0), bytesToWord(tweakBytes, 8)};
    }
    init(forEncryption, keyWords, tweakWords);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:56,代码来源:ThreefishEngine.java


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