本文整理汇总了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());
}
}
示例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));
}
示例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);
}