本文整理汇总了C#中IBlockCipher类的典型用法代码示例。如果您正苦于以下问题:C# IBlockCipher类的具体用法?C# IBlockCipher怎么用?C# IBlockCipher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IBlockCipher类属于命名空间,在下文中一共展示了IBlockCipher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AESCipherCBCnoPad
/** Creates a new instance of AESCipher */
public AESCipherCBCnoPad(bool forEncryption, byte[] key)
{
IBlockCipher aes = new AesFastEngine();
cbc = new CbcBlockCipher(aes);
KeyParameter kp = new KeyParameter(key);
cbc.Init(forEncryption, kp);
}
示例2: CMac
/**
* create a standard MAC based on a block cipher with the size of the
* MAC been given in bits.
* <p/>
* Note: the size of the MAC must be at least 24 bits (FIPS Publication 81),
* or 16 bits if being used as a data authenticator (FIPS Publication 113),
* and in general should be less than the size of the block cipher as it reduces
* the chance of an exhaustive attack (see Handbook of Applied Cryptography).
*
* @param cipher the cipher to be used as the basis of the MAC generation.
* @param macSizeInBits the size of the MAC in bits, must be a multiple of 8 and @lt;= 128.
*/
public CMac(
IBlockCipher cipher,
int macSizeInBits)
{
if ((macSizeInBits % 8) != 0)
throw new ArgumentException("MAC size must be multiple of 8");
if (macSizeInBits > (cipher.GetBlockSize() * 8))
{
throw new ArgumentException(
"MAC size must be less or equal to "
+ (cipher.GetBlockSize() * 8));
}
if (cipher.GetBlockSize() != 8 && cipher.GetBlockSize() != 16)
{
throw new ArgumentException(
"Block size must be either 64 or 128 bits");
}
this.cipher = new CbcBlockCipher(cipher);
this.macSize = macSizeInBits / 8;
mac = new byte[cipher.GetBlockSize()];
buf = new byte[cipher.GetBlockSize()];
ZEROES = new byte[cipher.GetBlockSize()];
bufOff = 0;
}
示例3: doWrapTest
private void doWrapTest(
int id,
IBlockCipher engine,
byte[] kek,
byte[] iv,
SecureRandom rand,
byte[] inBytes,
byte[] outBytes)
{
IWrapper wrapper = new Rfc3211WrapEngine(engine);
wrapper.Init(true, new ParametersWithRandom(
new ParametersWithIV(new KeyParameter(kek), iv), rand));
byte[] cText = wrapper.Wrap(inBytes, 0, inBytes.Length);
if (!AreEqual(cText, outBytes))
{
Fail("failed Wrap test " + id + " expected "
+ Hex.ToHexString(outBytes) + " got " + Hex.ToHexString(cText));
}
wrapper.Init(false, new ParametersWithIV(new KeyParameter(kek), iv));
byte[] pText = wrapper.Unwrap(outBytes, 0, outBytes.Length);
if (!AreEqual(pText, inBytes))
{
Fail("rfailed Unwrap test " + id + " expected "
+ Hex.ToHexString(inBytes) + " got " + Hex.ToHexString(pText));
}
}
示例4: BlockCipherMode
protected BlockCipherMode(IBlockCipher cipher)
{
if (cipher == null)
throw new ArgumentNullException("cipher", "Cipher cannot be null!");
this.cipher = cipher;
}
示例5: CfbBlockCipherMac
/**
* create a standard MAC based on a block cipher with the size of the
* MAC been given in bits. This class uses CFB mode as the basis for the
* MAC generation.
* <p>
* Note: the size of the MAC must be at least 24 bits (FIPS Publication 81),
* or 16 bits if being used as a data authenticator (FIPS Publication 113),
* and in general should be less than the size of the block cipher as it reduces
* the chance of an exhaustive attack (see Handbook of Applied Cryptography).
* </p>
* @param cipher the cipher to be used as the basis of the MAC generation.
* @param cfbBitSize the size of an output block produced by the CFB mode.
* @param macSizeInBits the size of the MAC in bits, must be a multiple of 8.
*/
public CfbBlockCipherMac(
IBlockCipher cipher,
int cfbBitSize,
int macSizeInBits)
: this(cipher, cfbBitSize, macSizeInBits, null)
{
}
示例6: GCMCipher
public GCMCipher(IBlockCipher cipher)
{
SecurityAssert.SAssert(cipher.BlockLength == 16);
SecurityAssert.SAssert(cipher.KeyLength >= 16);
Cipher = cipher;
buffer = new byte[BlockLength];
}
示例7: SicBlockCipher
/**
* Basic constructor.
*
* @param c the block cipher to be used.
*/
public SicBlockCipher(IBlockCipher cipher)
{
this.cipher = cipher;
this.blockSize = cipher.GetBlockSize();
this.IV = new byte[blockSize];
this.counter = new byte[blockSize];
this.counterOut = new byte[blockSize];
}
示例8: GcmBlockCipher
// Debug variables
// private int nCount, xCount, yCount;
public GcmBlockCipher(
IBlockCipher c)
{
if (c.GetBlockSize() != BlockSize)
throw new ArgumentException("cipher required with a block size of " + BlockSize + ".");
this.cipher = c;
}
示例9: BlockCipherModeUsingInitializationVector
protected BlockCipherModeUsingInitializationVector(IBlockCipher cipher, byte[] iv)
: base(cipher)
{
if (iv == null)
throw new ArgumentNullException("iv", "IV cannot be null!");
this.iv = iv;
}
示例10: Poly1305
/**
* Constructs a Poly1305 MAC, using a 128 bit block cipher.
*/
public Poly1305(IBlockCipher cipher)
{
if (cipher.GetBlockSize() != BLOCK_SIZE)
{
throw new ArgumentException("Poly1305 requires a 128 bit block cipher.");
}
this.cipher = cipher;
}
示例11: BufferedBlockCipher
/**
* Create a buffered block cipher without padding.
*
* @param cipher the underlying block cipher this buffering object wraps.
* false otherwise.
*/
public BufferedBlockCipher(IBlockCipher cipher)
{
if (cipher == null)
throw new ArgumentNullException("cipher");
this.Cipher = cipher;
this.Buffer = new byte[cipher.GetBlockSize()];
this.BufferOffset = 0;
}
示例12: CipherTest
// protected CipherTest(
// SimpleTest[] tests)
// {
// _tests = tests;
// }
protected CipherTest(
SimpleTest[] tests,
IBlockCipher engine,
KeyParameter validKey)
{
_tests = tests;
_engine = engine;
_validKey = validKey;
}
示例13: initCipher
private void initCipher(bool forEncryption, IBlockCipher cipher,
byte[] key_block, int key_size, int key_offset, int iv_offset)
{
KeyParameter key_parameter = new KeyParameter(key_block, key_offset,
key_size);
ParametersWithIV parameters_with_iv = new ParametersWithIV(
key_parameter, key_block, iv_offset, cipher.GetBlockSize());
cipher.Init(forEncryption, parameters_with_iv);
}
示例14: CcmBlockCipher
/**
* Basic constructor.
*
* @param cipher the block cipher to be used.
*/
public CcmBlockCipher(
IBlockCipher cipher)
{
this.cipher = cipher;
this.macBlock = new byte[BlockSize];
if (cipher.GetBlockSize() != BlockSize)
throw new ArgumentException("cipher required with a block size of " + BlockSize + ".");
}
示例15: CTR
public static CTR @new(IBlockCipher cipher, _counter counter)
{
CTR ctr = new CTR();
ctr.ucipher = cipher;
ctr.counter = counter;
ctr.counterOut = new byte[counter.Length];
ctr.count = 0;
return ctr;
}