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

C# ICipherParameters类代码示例

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

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



ICipherParameters类属于命名空间,在下文中一共展示了ICipherParameters类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
        }
开发者ID:dlech,项目名称:SshAgentLib,代码行数:30,代码来源:DesSsh1Engine.cs


示例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;
            }
        }
开发者ID:bitcoinkit,项目名称:BitcoinKit-CSharp,代码行数:40,代码来源:DesEdeEngine.cs


示例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;
        }
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:33,代码来源:RC532Engine.cs


示例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?
			}
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:31,代码来源:RFC3394WrapEngine.cs


示例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;
            }
        }
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:35,代码来源:SkipjackEngine.cs


示例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);
		}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:38,代码来源:Salsa20Engine.cs


示例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();
        }
开发者ID:will14smith,项目名称:Crypto,代码行数:25,代码来源:RSA.cs


示例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;
		}
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:29,代码来源:Salsa20Engine.cs


示例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);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:36,代码来源:DsaDigestSigner.cs


示例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);
        }
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:34,代码来源:CfbBlockCipherMac.cs


示例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;
        }
开发者ID:bitcoinkit,项目名称:BitcoinKit-CSharp,代码行数:39,代码来源:HC256Engine.cs


示例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();
 }
开发者ID:VahidN,项目名称:PdfReport,代码行数:10,代码来源:SignatureWriter.cs


示例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);
			}
		}
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:33,代码来源:KeyTransRecipientInformation.cs


示例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);
        }
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:29,代码来源:HMac.cs


示例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;
		}
开发者ID:htlp,项目名称:itextsharp,代码行数:25,代码来源:DHAgreement.cs


示例16: 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.
        *
        * @param forEncryption if true the cipher is initialised for
        *  encryption, if false for decryption.
        * @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)
        {
            bool oldEncrypting = this.encrypting;

            this.encrypting = forEncryption;

            if (parameters is ParametersWithIV)
            {
                ParametersWithIV ivParam = (ParametersWithIV)parameters;
                byte[]      iv = ivParam.GetIV();

                if (iv.Length != blockSize)
                {
                    throw new ArgumentException("initialisation vector must be the same length as block size");
                }

                Array.Copy(iv, 0, IV, 0, iv.Length);

				parameters = ivParam.Parameters;
            }

			Reset();

            // if null it's an IV changed only.
            if (parameters != null)
            {
                cipher.Init(encrypting, parameters);
            }
            else if (oldEncrypting != encrypting)
            {
                throw new ArgumentException("cannot change encrypting state without providing key.");
            }
        }
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:45,代码来源:CbcBlockCipher.cs


示例17: Init

        public virtual void Init(
            bool				forEncryption,
            ICipherParameters	parameters)
        {
            this.forEncryption = forEncryption;

            if (parameters is AeadParameters)
            {
                AeadParameters param = (AeadParameters) parameters;

                nonce = param.GetNonce();
                initialAssociatedText = param.GetAssociatedText();
                macSize = param.MacSize / 8;
                keyParam = param.Key;
            }
            else if (parameters is ParametersWithIV)
            {
                ParametersWithIV param = (ParametersWithIV) parameters;

                nonce = param.GetIV();
                initialAssociatedText = null;
                macSize = macBlock.Length / 2;
                keyParam = param.Parameters;
            }
            else
            {
                throw new ArgumentException("invalid parameters passed to CCM");
            }

            if (nonce == null || nonce.Length < 7 || nonce.Length > 13)
            {
                throw new ArgumentException("nonce must have length from 7 to 13 octets");
            }
        }
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:34,代码来源:CcmBlockCipher.cs


示例18: Init

        public void Init(bool forSigning, ICipherParameters parameters)
        {
            if (forSigning)
            {
                if (parameters is ParametersWithRandom)
                {
                    var rParam = (ParametersWithRandom)parameters;

                    _random = rParam.Random;
                    parameters = rParam.Parameters;
                }
                else
                {
                    _random = new SecureRandom();
                }

                if (!(parameters is DsaPrivateKeyParameters))
                    throw new InvalidKeyException("DSA private key required for signing");

                _key = (DsaPrivateKeyParameters)parameters;
            }
            else
            {
                if (!(parameters is DsaPublicKeyParameters))
                    throw new InvalidKeyException("DSA public key required for verification");

                _key = (DsaPublicKeyParameters)parameters;
            }
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:29,代码来源:DsaSigner.cs


示例19: Init

        public void Init(
			bool				forSigning,
			ICipherParameters	parameters)
        {
            if (forSigning)
            {
                if (parameters is ParametersWithRandom)
                {
                    ParametersWithRandom rParam = (ParametersWithRandom)parameters;

                    this.random = rParam.Random;
            //					this.key = (Gost3410PrivateKeyParameters)rParam.Parameters;
                    parameters = rParam.Parameters;
                }
                else
                {
                    this.random = new SecureRandom();
            //					this.key = (Gost3410PrivateKeyParameters)parameters;
                }

                if (!(parameters is Gost3410PrivateKeyParameters))
                    throw new InvalidKeyException("GOST3410 private key required for signing");

                this.key = (Gost3410PrivateKeyParameters) parameters;
            }
            else
            {
                if (!(parameters is Gost3410PublicKeyParameters))
                    throw new InvalidKeyException("GOST3410 public key required for signing");

                this.key = (Gost3410PublicKeyParameters) parameters;
            }
        }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:33,代码来源:GOST3410Signer.cs


示例20: Init

		public void Init(
			bool				forSigning,
			ICipherParameters	parameters)
		{
			this.forSigning = forSigning;

			AsymmetricKeyParameter k;
			if (parameters is ParametersWithRandom)
			{
				k = (AsymmetricKeyParameter)((ParametersWithRandom)parameters).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.");
			}

			Reset();

			dsaSigner.Init(forSigning, parameters);
		}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:30,代码来源:GOST3410DigestSigner.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# ICirData类代码示例发布时间:2022-05-24
下一篇:
C# IChunk类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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