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


C# Parameters.KeyParameter类代码示例

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


KeyParameter类属于Org.BouncyCastle.Crypto.Parameters命名空间,在下文中一共展示了KeyParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Hash

        private byte[] Hash()
        {
            byte[] array = DataConverter.BigEndian.GetBytes(block);
            ICipherParameters param = new KeyParameter(password);

            hMac.Init(param);
            hMac.BlockUpdate(salt, 0, salt.Length);

            hMac.BlockUpdate(array, 0, array.Length);
            byte[] array2 = new byte[20];
            hMac.DoFinal(array2, 0);

            hMac.Init(param);

            byte[] array3 = new byte[20];
            Buffer.BlockCopy(array2, 0, array3, 0, 20);
            int num = 2;
            while (num <= (long)((ulong)iterations))
            {
                hMac.BlockUpdate(array2, 0, array2.Length);
                hMac.DoFinal(array2, 0);
                for (int i = 0; i < 20; i++)
                {
                    array3[i] ^= array2[i];
                }
                num++;
            }
            block += 1u;
            return array3;
        }
开发者ID:kouseki926,项目名称:sharpcompress,代码行数:30,代码来源:PBKDF2.cs

示例2: 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);
 }
开发者ID:jomamorales,项目名称:createPDF,代码行数:8,代码来源:AESCipher.cs

示例3: PerformTest

		public override void PerformTest()
		{
			byte[] key = Hex.Decode("9661410AB797D8A9EB767C21172DF6C7");
			byte[] iv = Hex.Decode("4B5C2F003E67F39557A8D26F3DA2B155");
			ICipherParameters kp = new KeyParameter(key);
			ICipherParameters kpwiv = new ParametersWithIV(kp, iv);

			VmpcKsa3Engine engine = new VmpcKsa3Engine();

			try
			{
				engine.Init(true, kp);
				Fail("Init failed to throw expected exception");
			}
			catch (ArgumentException)
			{
				// Expected
			}

			engine.Init(true, kpwiv);
			checkEngine(engine);

			engine.Reset();
			byte[] output = checkEngine(engine);

			engine.Init(false, kpwiv);
			byte[] recovered = new byte[output.Length];
			engine.ProcessBytes(output, 0, output.Length, recovered, 0);

			if (!Arrays.AreEqual(input, recovered))
			{
				Fail("decrypted bytes differ from original bytes");
			}
		}
开发者ID:randombit,项目名称:hacrypto,代码行数:34,代码来源:VMPCKSA3Test.cs

示例4: Chacha20Poly1305

        /// <exception cref="IOException"></exception>
        public Chacha20Poly1305(TlsContext context)
        {
            if (!TlsUtilities.IsTlsV12(context))
                throw new TlsFatalAlert(AlertDescription.internal_error);

            this.context = context;

            byte[] key_block = TlsUtilities.CalculateKeyBlock(context, 64);

            KeyParameter client_write_key = new KeyParameter(key_block, 0, 32);
            KeyParameter server_write_key = new KeyParameter(key_block, 32, 32);

            this.encryptCipher = new ChaChaEngine(20);
            this.decryptCipher = new ChaChaEngine(20);

            KeyParameter encryptKey, decryptKey;
            if (context.IsServer)
            {
                encryptKey = server_write_key;
                decryptKey = client_write_key;
            }
            else
            {
                encryptKey = client_write_key;
                decryptKey = server_write_key;
            }

            byte[] dummyNonce = new byte[8];

            this.encryptCipher.Init(true, new ParametersWithIV(encryptKey, dummyNonce));
            this.decryptCipher.Init(false, new ParametersWithIV(decryptKey, dummyNonce));
        }
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:33,代码来源:Chacha20Poly1305.cs

示例5: PerformTest

		public override void PerformTest()
		{
			ICipherParameters kp = new KeyParameter(
				Hex.Decode("9661410AB797D8A9EB767C21172DF6C7"));
			ICipherParameters kpwiv = new ParametersWithIV(kp,
				Hex.Decode("4B5C2F003E67F39557A8D26F3DA2B155"));

            int offset = 117;
            byte[] m = new byte[512];
			for (int i = 0; i < 256; i++)
			{
				m[offset + i] = (byte)i;
			}

            VmpcMac mac = new VmpcMac();
			mac.Init(kpwiv);

			mac.BlockUpdate(m, offset, 256);

			byte[] output = new byte[20];
			mac.DoFinal(output, 0);

			if (!Arrays.AreEqual(output, output1))
			{
				Fail("Fail",
					Hex.ToHexString(output1),
					Hex.ToHexString(output));
			}
		}
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:29,代码来源:VMPCMacTest.cs

示例6: Generate

		public RecipientInfo Generate(KeyParameter contentEncryptionKey, SecureRandom random)
		{
			byte[] keyBytes = contentEncryptionKey.GetKey();

			string rfc3211WrapperName = Helper.GetRfc3211WrapperName(keyEncryptionKeyOID);
			IWrapper keyWrapper = Helper.CreateWrapper(rfc3211WrapperName);

			// Note: In Java build, the IV is automatically generated in JCE layer
			int ivLength = Platform.StartsWith(rfc3211WrapperName, "DESEDE") ? 8 : 16;
			byte[] iv = new byte[ivLength];
			random.NextBytes(iv);

			ICipherParameters parameters = new ParametersWithIV(keyEncryptionKey, iv);
			keyWrapper.Init(true, new ParametersWithRandom(parameters, random));
        	Asn1OctetString encryptedKey = new DerOctetString(
				keyWrapper.Wrap(keyBytes, 0, keyBytes.Length));

			DerSequence seq = new DerSequence(
				new DerObjectIdentifier(keyEncryptionKeyOID),
				new DerOctetString(iv));

			AlgorithmIdentifier keyEncryptionAlgorithm = new AlgorithmIdentifier(
				PkcsObjectIdentifiers.IdAlgPwriKek, seq);

			return new RecipientInfo(new PasswordRecipientInfo(
				keyDerivationAlgorithm, keyEncryptionAlgorithm, encryptedKey));
		}
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:27,代码来源:PasswordRecipientInfoGenerator.cs

示例7: CreateParametersWithIV

        protected virtual ParametersWithIV CreateParametersWithIV(KeyParameter key,
			byte[] buf, ref int off, int len)
		{
			ParametersWithIV ivParams = new ParametersWithIV(key, buf, off, len);
			off += len;
			return ivParams;
		}
开发者ID:zzilla,项目名称:ONVIF-Device-Manager,代码行数:7,代码来源:TlsBlockCipher.cs

示例8: 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:ktw,项目名称:OutlookPrivacyPlugin,代码行数:31,代码来源:RFC3394WrapEngine.cs

示例9: blockCheck

		private void blockCheck(
			PaddedBufferedBlockCipher   cipher,
			IBlockCipherPadding          padding,
			KeyParameter                key,
			byte[]                      data)
		{
			byte[]  outBytes = new byte[data.Length + 8];
			byte[]  dec = new byte[data.Length];

			try
			{
				cipher.Init(true, key);

				int    len = cipher.ProcessBytes(data, 0, data.Length, outBytes, 0);

				len += cipher.DoFinal(outBytes, len);

				cipher.Init(false, key);

				int    decLen = cipher.ProcessBytes(outBytes, 0, len, dec, 0);

				decLen += cipher.DoFinal(dec, decLen);

				if (!AreEqual(data, dec))
				{
					Fail("failed to decrypt - i = " + data.Length + ", padding = " + padding.PaddingName);
				}
			}
			catch (Exception e)
			{
				Fail("Exception - " + e.ToString(), e);
			}
		}
开发者ID:randombit,项目名称:hacrypto,代码行数:33,代码来源:PaddingTest.cs

示例10: GenerateDerivedKey

        private byte[] GenerateDerivedKey(
            int dkLen)
        {
            int     hLen = hMac.GetMacSize();
            int     l = (dkLen + hLen - 1) / hLen;
            byte[]  iBuf = new byte[4];
            byte[]  outBytes = new byte[l * hLen];
            int     outPos = 0;

            ICipherParameters param = new KeyParameter(mPassword);

            hMac.Init(param);

            for (int i = 1; i <= l; i++)
            {
                // Increment the value in 'iBuf'
                int pos = 3;
                while (++iBuf[pos] == 0)
                {
                    --pos;
                }

                F(mSalt, mIterationCount, iBuf, outBytes, outPos);
                outPos += hLen;
            }

            return outBytes;
        }
开发者ID:gkardava,项目名称:WinPass,代码行数:28,代码来源:Pkcs5S2ParametersGenerator.cs

示例11: CreateRijndael

 private IBufferedCipher CreateRijndael(WinzipAesEncryptionData winzipAesEncryptionData)
 {
     var blockCipher = new BufferedBlockCipher(new RijndaelEngine());
     var param = new KeyParameter(winzipAesEncryptionData.KeyBytes);
     blockCipher.Init(true, param);
     return blockCipher;
 }
开发者ID:kuzn-ilya,项目名称:sharpcompress,代码行数:7,代码来源:WinzipAesCryptoStream.Portable.cs

示例12: CcmParameters

 /**
  * Base constructor.
  *
  * @param key key to be used by underlying cipher
  * @param macSize macSize in bits
  * @param nonce nonce to be used
  * @param associatedText associated text, if any
  */
 public CcmParameters(KeyParameter key, int macSize, byte[] nonce, byte[] associatedText)
 {
     this.key = key;
     this.nonce = nonce;
     this.macSize = macSize;
     this.associatedText = associatedText;
 }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:15,代码来源:CcmParameters.cs

示例13: DecodeCryptogram

        public void DecodeCryptogram(string key)
        {
            byte[] result = new byte[cryptogramByte.Count];
            byte[] pass = Encoding.ASCII.GetBytes(key);

            try
            {
            RC4Engine rc4 = new RC4Engine();
            KeyParameter keyParam = new KeyParameter(pass);
            rc4.Init(true, keyParam);
            rc4.ProcessBytes(cryptogramByte.ToArray(), 0, cryptogramByte.Count, result, 0);
            }
            catch (Exception e)
            {
            Console.WriteLine(e.Message);
            }

            if (CheckDecryptedText(result))
            {
            Console.Write("klucz: " + key + ": ");

            foreach (var c in result)
            {
                if (c != 0)
                {
                    Console.Write((char)c);
                }
            }
            Console.WriteLine();
            }
        }
开发者ID:Mirkoslaw,项目名称:KryptografiaLista1,代码行数:31,代码来源:Zadanie2Method.cs

示例14: AESCipher

 /** Creates a new instance of AESCipher */
 public AESCipher(bool forEncryption, byte[] key, byte[] iv) {
     IBlockCipher aes = new AesFastEngine();
     IBlockCipher cbc = new CbcBlockCipher(aes);
     bp = new PaddedBufferedBlockCipher(cbc);
     KeyParameter kp = new KeyParameter(key);
     ParametersWithIV piv = new ParametersWithIV(kp, iv);
     bp.Init(forEncryption, piv);
 }
开发者ID:nicecai,项目名称:iTextSharp-4.1.6,代码行数:9,代码来源:AESCipher.cs

示例15: checkKeyParameter

		private void checkKeyParameter(
			KeyParameter	key,
			Type			expectedType,
			byte[]			expectedBytes)
		{
			Assert.IsTrue(expectedType.IsInstanceOfType(key));
			Assert.IsTrue(Arrays.AreEqual(expectedBytes, key.GetKey()));
		}
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:8,代码来源:TestParameterUtil.cs


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