本文整理汇总了C#中ICipherParameters类的典型用法代码示例。如果您正苦于以下问题:C# ICipherParameters类的具体用法?C# ICipherParameters怎么用?C# ICipherParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICipherParameters类属于命名空间,在下文中一共展示了ICipherParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init(bool encrypting, ICipherParameters parameters)
{
if (!(parameters is KeyParameter))
{
throw new ArgumentException("Invalid parameter passed to "+
"DesSsh1Engine init - " + parameters.GetType());
}
this.encrypting = encrypting;
byte[] passphraseKey = (parameters as KeyParameter).GetKey();
if (passphraseKey.Length !=16)
{
throw new ArgumentException("key size different than 16 bytes");
}
byte[] keyPart1 = new byte[8];
byte[] keyPart2 = new byte[8];
Array.Copy(passphraseKey, keyPart1, 8);
Array.Copy(passphraseKey, 8, keyPart2, 0, 8);
desEngine1 = new CbcBlockCipher(new DesEngine());
desEngine2 = new CbcBlockCipher(new DesEngine());
desEngine3 = new CbcBlockCipher(new DesEngine());
desEngine1.Init(encrypting, new KeyParameter(keyPart1));
desEngine2.Init(!encrypting, new KeyParameter(keyPart2));
desEngine3.Init(encrypting, new KeyParameter(keyPart1));
}
示例2: Init
/**
* initialise a DESede cipher.
*
* @param forEncryption whether or not we are for encryption.
* @param parameters the parameters required to set up the cipher.
* @exception ArgumentException if the parameters argument is
* inappropriate.
*/
public override void Init(
bool forEncryption,
ICipherParameters parameters)
{
if (!(parameters is KeyParameter))
throw new ArgumentException("invalid parameter passed to DESede init - " + parameters.GetType().ToString());
byte[] keyMaster = ((KeyParameter)parameters).GetKey();
if (keyMaster.Length != 24 && keyMaster.Length != 16)
throw new ArgumentException("key size must be 16 or 24 bytes.");
this.forEncryption = forEncryption;
byte[] key1 = new byte[8];
Array.Copy(keyMaster, 0, key1, 0, key1.Length);
workingKey1 = GenerateWorkingKey(forEncryption, key1);
byte[] key2 = new byte[8];
Array.Copy(keyMaster, 8, key2, 0, key2.Length);
workingKey2 = GenerateWorkingKey(!forEncryption, key2);
if (keyMaster.Length == 24)
{
byte[] key3 = new byte[8];
Array.Copy(keyMaster, 16, key3, 0, key3.Length);
workingKey3 = GenerateWorkingKey(forEncryption, key3);
}
else // 16 byte key
{
workingKey3 = workingKey1;
}
}
示例3: Init
/**
* initialise a RC5-32 cipher.
*
* @param forEncryption whether or not we are for encryption.
* @param parameters the parameters required to set up the cipher.
* @exception ArgumentException if the parameters argument is
* inappropriate.
*/
public virtual void Init(
bool forEncryption,
ICipherParameters parameters)
{
if (typeof(RC5Parameters).IsInstanceOfType(parameters))
{
RC5Parameters p = (RC5Parameters)parameters;
_noRounds = p.Rounds;
SetKey(p.GetKey());
}
else if (typeof(KeyParameter).IsInstanceOfType(parameters))
{
KeyParameter p = (KeyParameter)parameters;
SetKey(p.GetKey());
}
else
{
throw new ArgumentException("invalid parameter passed to RC532 init - " + Platform.GetTypeName(parameters));
}
this.forEncryption = forEncryption;
}
示例4: Init
public void Init(
bool forWrapping,
ICipherParameters parameters)
{
this.forWrapping = forWrapping;
if (parameters is ParametersWithRandom)
{
parameters = ((ParametersWithRandom) parameters).Parameters;
}
if (parameters is KeyParameter)
{
this.param = (KeyParameter) parameters;
}
else if (parameters is ParametersWithIV)
{
ParametersWithIV pIV = (ParametersWithIV) parameters;
byte[] iv = pIV.GetIV();
if (iv.Length != 8)
throw new ArgumentException("IV length not equal to 8", "parameters");
this.iv = iv;
this.param = (KeyParameter) pIV.Parameters;
}
else
{
// TODO Throw an exception for bad parameters?
}
}
示例5: Init
/**
* initialise a SKIPJACK cipher.
*
* @param forEncryption whether or not we are for encryption.
* @param parameters the parameters required to set up the cipher.
* @exception ArgumentException if the parameters argument is
* inappropriate.
*/
public virtual void Init(
bool forEncryption,
ICipherParameters parameters)
{
if (!(parameters is KeyParameter))
throw new ArgumentException("invalid parameter passed to SKIPJACK init - " + parameters.GetType().ToString());
byte[] keyBytes = ((KeyParameter)parameters).GetKey();
this.encrypting = forEncryption;
this.key0 = new int[32];
this.key1 = new int[32];
this.key2 = new int[32];
this.key3 = new int[32];
//
// expand the key to 128 bytes in 4 parts (saving us a modulo, multiply
// and an addition).
//
for (int i = 0; i < 32; i ++)
{
key0[i] = keyBytes[(i * 4) % 10] & 0xff;
key1[i] = keyBytes[(i * 4 + 1) % 10] & 0xff;
key2[i] = keyBytes[(i * 4 + 2) % 10] & 0xff;
key3[i] = keyBytes[(i * 4 + 3) % 10] & 0xff;
}
}
示例6: Init
/**
* initialise a Salsa20 cipher.
*
* @param forEncryption whether or not we are for encryption.
* @param params the parameters required to set up the cipher.
* @exception ArgumentException if the params argument is
* inappropriate.
*/
public void Init(
bool forEncryption,
ICipherParameters parameters)
{
/*
* Salsa20 encryption and decryption is completely
* symmetrical, so the 'forEncryption' is
* irrelevant. (Like 90% of stream ciphers)
*/
ParametersWithIV ivParams = parameters as ParametersWithIV;
if (ivParams == null)
throw new ArgumentException("Salsa20 Init requires an IV", "parameters");
byte[] iv = ivParams.GetIV();
if (iv == null || iv.Length != 8)
throw new ArgumentException("Salsa20 requires exactly 8 bytes of IV");
KeyParameter key = ivParams.Parameters as KeyParameter;
if (key == null)
throw new ArgumentException("Salsa20 Init requires a key", "parameters");
workingKey = key.GetKey();
workingIV = iv;
setKey(workingKey, workingIV);
}
示例7: Init
public void Init(ICipherParameters parameters)
{
var pubKeyParams = parameters as PublicKeyParameter;
if (pubKeyParams != null)
{
SecurityAssert.SAssert(pubKeyParams.Key is RSAPublicKey);
pub = (RSAPublicKey)pubKeyParams.Key;
return;
}
var privKeyParams = parameters as PrivateKeyParameter;
if (privKeyParams != null)
{
SecurityAssert.SAssert(privKeyParams.Key is RSAPrivateKey);
priv = (RSAPrivateKey)privKeyParams.Key;
pub = (RSAPublicKey)priv.PublicKey;
return;
}
throw new InvalidCastException();
}
示例8: Init
public void Init(
bool forEncryption,
ICipherParameters parameters)
{
/*
* Salsa20 encryption and decryption is completely
* symmetrical, so the 'forEncryption' is
* irrelevant. (Like 90% of stream ciphers)
*/
ParametersWithIV ivParams = parameters as ParametersWithIV;
if (ivParams == null)
throw new ArgumentException(AlgorithmName + " Init requires an IV", "parameters");
byte[] iv = ivParams.GetIV();
if (iv == null || iv.Length != NonceSize)
throw new ArgumentException(AlgorithmName + " requires exactly " + NonceSize + " bytes of IV");
KeyParameter key = ivParams.Parameters as KeyParameter;
if (key == null)
throw new ArgumentException(AlgorithmName + " Init requires a key", "parameters");
SetKey(key.GetKey(), iv);
Reset();
initialised = true;
}
示例9: Init
/// <summary>
/// Initialise the signer for signing or verification.
/// </summary>
/// <param name="forSigning"></param>
/// <param name="parameters"></param>
/// <exception cref="InvalidKeyException">
/// Signing Requires Private Key.
/// or
/// Verification Requires Public Key.
/// </exception>
public void Init(bool forSigning, ICipherParameters parameters)
{
_forSigning = forSigning;
IAsymmetricKeyParameter k;
var parametersWithRandom = parameters as ParametersWithRandom;
if (parametersWithRandom != null)
{
k = (AsymmetricKeyParameter)parametersWithRandom.Parameters;
}
else
{
k = (AsymmetricKeyParameter)parameters;
}
if (forSigning && !k.IsPrivate)
throw new InvalidKeyException("Signing Requires Private Key.");
if (!forSigning && k.IsPrivate)
throw new InvalidKeyException("Verification Requires Public Key.");
this.Reset();
_dsaSigner.Init(forSigning, parameters);
}
示例10: Init
/**
* Initialise the cipher and, possibly, the initialisation vector (IV).
* If an IV isn't passed as part of the parameter, the IV will be all zeros.
* An IV which is too short is handled in FIPS compliant fashion.
*
* @param param the key and other data required by the cipher.
* @exception ArgumentException if the parameters argument is
* inappropriate.
*/
public void Init(
bool forEncryption,
ICipherParameters parameters)
{
if (parameters is ParametersWithIV)
{
ParametersWithIV ivParam = (ParametersWithIV)parameters;
byte[] iv = ivParam.GetIV();
if (iv.Length < IV.Length)
{
Array.Copy(iv, 0, IV, IV.Length - iv.Length, iv.Length);
}
else
{
Array.Copy(iv, 0, IV, 0, IV.Length);
}
parameters = ivParam.Parameters;
}
Reset();
cipher.Init(true, parameters);
}
示例11: Init
/**
* Initialise a HC-256 cipher.
*
* @param forEncryption whether or not we are for encryption. Irrelevant, as
* encryption and decryption are the same.
* @param params the parameters required to set up the cipher.
* @throws ArgumentException if the params argument is
* inappropriate (ie. the key is not 256 bit long).
*/
public void Init(
bool forEncryption,
ICipherParameters parameters)
{
ICipherParameters keyParam = parameters;
if (parameters is ParametersWithIV)
{
iv = ((ParametersWithIV)parameters).GetIV();
keyParam = ((ParametersWithIV)parameters).Parameters;
}
else
{
iv = new byte[0];
}
if (keyParam is KeyParameter)
{
key = ((KeyParameter)keyParam).GetKey();
Init();
}
else
{
throw new ArgumentException(
"Invalid parameter passed to HC256 init - " + parameters.GetType().Name,
"parameters");
}
initialised = true;
}
示例12: CustomPdfReader
/// <summary>
/// CustomPdfReader to be able to work with streams.
/// </summary>
public CustomPdfReader(Stream isp, X509Certificate certificate, ICipherParameters certificateKey)
{
this.certificate = certificate;
this.certificateKey = certificateKey;
tokens = new PRTokeniser(new RandomAccessFileOrArray(isp));
ReadPdf();
}
示例13: UnwrapKey
internal KeyParameter UnwrapKey(ICipherParameters key)
{
byte[] encryptedKey = info.EncryptedKey.GetOctets();
string keyExchangeAlgorithm = GetExchangeEncryptionAlgorithmName(keyEncAlg.Algorithm);
try
{
IWrapper keyWrapper = WrapperUtilities.GetWrapper(keyExchangeAlgorithm);
keyWrapper.Init(false, key);
// FIXME Support for MAC algorithm parameters similar to cipher parameters
return ParameterUtilities.CreateKeyParameter(
GetContentAlgorithmName(), keyWrapper.Unwrap(encryptedKey, 0, encryptedKey.Length));
}
catch (SecurityUtilityException e)
{
throw new CmsException("couldn't create cipher.", e);
}
catch (InvalidKeyException e)
{
throw new CmsException("key invalid in message.", e);
}
// catch (IllegalBlockSizeException e)
catch (DataLengthException e)
{
throw new CmsException("illegal blocksize in message.", e);
}
// catch (BadPaddingException e)
catch (InvalidCipherTextException e)
{
throw new CmsException("bad padding in message.", e);
}
}
示例14: Init
public void Init(
ICipherParameters parameters)
{
digest.Reset();
byte[] key = ((KeyParameter)parameters).GetKey();
int keyLength = key.Length;
if (keyLength > blockLength)
{
digest.BlockUpdate(key, 0, key.Length);
digest.DoFinal(inputPad, 0);
keyLength = digestSize;
}
else
{
Array.Copy(key, 0, inputPad, 0, keyLength);
}
Array.Clear(inputPad, keyLength, blockLength - keyLength);
Array.Copy(inputPad, 0, outputPad, 0, blockLength);
xor(inputPad, IPAD);
xor(outputPad, OPAD);
// Initialise the digest
digest.BlockUpdate(inputPad, 0, inputPad.Length);
}
示例15: Init
public void Init(
ICipherParameters parameters)
{
AsymmetricKeyParameter kParam;
if (parameters is ParametersWithRandom)
{
ParametersWithRandom rParam = (ParametersWithRandom)parameters;
this.random = rParam.Random;
kParam = (AsymmetricKeyParameter)rParam.Parameters;
}
else
{
this.random = new SecureRandom();
kParam = (AsymmetricKeyParameter)parameters;
}
if (!(kParam is DHPrivateKeyParameters))
{
throw new ArgumentException("DHEngine expects DHPrivateKeyParameters");
}
this.key = (DHPrivateKeyParameters)kParam;
this.dhParams = key.Parameters;
}