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


C# ICryptoTransform.TransformBlock方法代码示例

本文整理汇总了C#中ICryptoTransform.TransformBlock方法的典型用法代码示例。如果您正苦于以下问题:C# ICryptoTransform.TransformBlock方法的具体用法?C# ICryptoTransform.TransformBlock怎么用?C# ICryptoTransform.TransformBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICryptoTransform的用法示例。


在下文中一共展示了ICryptoTransform.TransformBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvalidInput_Base64Transform

        private void InvalidInput_Base64Transform(ICryptoTransform transform)
        {
            byte[] data_4bytes = Text.Encoding.ASCII.GetBytes("aaaa");

            Assert.Throws<ArgumentNullException>("inputBuffer", () => transform.TransformBlock(null, 0, 0, null, 0));
            Assert.Throws<ArgumentOutOfRangeException>("inputOffset", () => transform.TransformBlock(Array.Empty<byte>(), -1, 0, null, 0));
            Assert.Throws<ArgumentNullException>("dst", () => transform.TransformBlock(data_4bytes, 0, 4, null, 0));
            Assert.Throws<ArgumentException>(null, () => transform.TransformBlock(Array.Empty<byte>(), 0, 1, null, 0));
            Assert.Throws<ArgumentException>(null, () => transform.TransformBlock(Array.Empty<byte>(), 1, 0, null, 0));

            Assert.Throws<ArgumentNullException>("inputBuffer", () => transform.TransformFinalBlock(null, 0, 0));
            Assert.Throws<ArgumentOutOfRangeException>("inputOffset", () => transform.TransformFinalBlock(Array.Empty<byte>(), -1, 0));
            Assert.Throws<ArgumentOutOfRangeException>("inputOffset", () => transform.TransformFinalBlock(Array.Empty<byte>(), -1, 0));
            Assert.Throws<ArgumentException>(null, () => transform.TransformFinalBlock(Array.Empty<byte>(), 1, 0));
        }
开发者ID:Corillian,项目名称:corefx,代码行数:15,代码来源:Base64TransformsTests.cs

示例2: Initialize

		public override void Initialize ()
		{
			_ct = _algo.CreateEncryptor ();
			_k1 = new byte[_algo.BlockSize >> 3];
			_k2 = new byte[_k1.Length];
			_state = new byte[_k1.Length];
			_buf = new byte[_k1.Length];
			_bufFilled = 0;
			byte[] R = (_algo.BlockSize == 64 ? R_64 : R_128);

			_ct.TransformBlock (new byte[_k1.Length], 0, _k1.Length, _k1, 0);
			int msb = MSB_1 (_k1);
			LeftShift_1 (_k1);
			if (msb != 0) {
				for (int i = 0; i < _k1.Length; i++)
					_k1[i] ^= R[i];
			}

			Buffer.BlockCopy (_k1, 0, _k2, 0, _k2.Length);
			LeftShift_1 (_k2);
			if (MSB_1 (_k1) != 0) {
				for (int i = 0; i < _k2.Length; i++)
					_k2[i] ^= R[i];
			}
		}
开发者ID:kazuki,项目名称:opencrypto.net,代码行数:25,代码来源:CMAC.cs

示例3: CheckCBC

		public void CheckCBC(ICryptoTransform encryptor, ICryptoTransform decryptor, 
					   byte[] plaintext, byte[] expected) 
		{
	
			if ((plaintext.Length % encryptor.InputBlockSize) != 0) {
				throw new ArgumentException("Must have complete blocks");
			}
	
			byte[] ciphertext = new byte[plaintext.Length];
			for (int i=0; i < plaintext.Length; i += encryptor.InputBlockSize) {
				encryptor.TransformBlock(plaintext, i, encryptor.InputBlockSize, ciphertext, i);
			}
	
			for (int i=0; i<32; i++) {
				AssertEquals("CBC-" + i, expected[i], ciphertext[i]);
			}
	
			byte[] roundtrip = new byte[plaintext.Length];
			for (int i=0; i < ciphertext.Length; i += decryptor.InputBlockSize) {
				decryptor.TransformBlock(ciphertext, i, decryptor.InputBlockSize, roundtrip, i);
			}
	
			for (int i=0; i<32; i++) {
				AssertEquals("CBC-rt-" + i, roundtrip[i], plaintext[i]);
			}
	
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:27,代码来源:RijndaelManagedTest.cs

示例4: Decrypt

private void Decrypt (ICryptoTransform trans, byte[] input, byte[] output)
{
	int bs = trans.InputBlockSize;
	int full = input.Length / bs;
	int partial = input.Length % bs;
	int pos = 0;
	for (int i=0; i < full; i++) {
		trans.TransformBlock (input, pos, bs, output, pos);
		pos += bs;
	}
	if (partial > 0) {
		byte[] final = trans.TransformFinalBlock (input, pos, partial);
		Array.Copy (final, 0, output, pos, partial);
	}
}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:15,代码来源:SymmetricAlgorithmTest.cs

示例5: CheckCBC

		public void CheckCBC(ICryptoTransform encryptor, ICryptoTransform decryptor, 
					   byte[] plaintext, byte[] expected) 
		{
	
			if ((plaintext.Length % encryptor.InputBlockSize) != 0) {
				throw new ArgumentException("Must have complete blocks");
			}
	
			byte[] ciphertext = new byte[plaintext.Length];
			for (int i=0; i < plaintext.Length; i += encryptor.InputBlockSize) {
				encryptor.TransformBlock(plaintext, i, encryptor.InputBlockSize, ciphertext, i);
			}
			Assert.AreEqual (expected, ciphertext, "CBC");
	
			byte[] roundtrip = new byte[plaintext.Length];
			for (int i=0; i < ciphertext.Length; i += decryptor.InputBlockSize) {
				decryptor.TransformBlock(ciphertext, i, decryptor.InputBlockSize, roundtrip, i);
			}
			Assert.AreEqual (plaintext, roundtrip, "CBC-rt");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:20,代码来源:RijndaelManagedTest.cs

示例6: TransformMultiByte

 void TransformMultiByte(byte[] input, byte[] output, ICryptoTransform transform)
 {
     if (input.Length != output.Length)
     {
         throw new Exception("Input and output size must match");
     }
     if (testmode)
     {
         Buffer.BlockCopy(input, 0, output, 0, output.Length);
         return;
     }
     int ib = transform.InputBlockSize;
     if (transform.CanTransformMultipleBlocks)
     {
         transform.TransformBlock(input, 0, output.Length, output, 0);
     }else {
         for (int i = 0; i < output.Length; i += ib)
         {
             transform.TransformBlock(input, i, ib, output, i);
         }
     }
 }
开发者ID:IDWMaster,项目名称:IDWOS2012,代码行数:22,代码来源:crypthelpers.cs

示例7: TransformRecordBytes

        private static byte[] TransformRecordBytes(BulkCipherAlgorithmType cipherType, ICryptoTransform transform, byte[] input)
        {
            if (cipherType != BulkCipherAlgorithmType.AEAD) {
                // In case of non-AEAD cipher algorithm, check that data matches block size
                if (input.Length % transform.InputBlockSize != 0) {
                    throw new Exception("Input data size doesn't match block size");
                }
            }

            int blockCount = input.Length / transform.InputBlockSize;
            if (cipherType == BulkCipherAlgorithmType.AEAD) {
                // Make sure there is enough data at TransformFinalBlock, because
                // decryption requires that the authentication tag is present
                if (blockCount > 0) {
                    blockCount--;
                }
            }

            byte[] output = new byte[blockCount * transform.OutputBlockSize];
            if (transform.CanTransformMultipleBlocks) {
                transform.TransformBlock(input, 0, blockCount*transform.InputBlockSize, output, 0);
            } else {
                for (int i=0; i<blockCount; i++) {
                    transform.TransformBlock(input, i*transform.InputBlockSize,
                                             transform.InputBlockSize,
                                             output, i*transform.OutputBlockSize);
                }
            }

            if (cipherType == BulkCipherAlgorithmType.AEAD) {
                int currentPosition = blockCount*transform.InputBlockSize;

                // Transfer the last block when encrypting or authentication tag when decrypting
                byte[] finalBytes = transform.TransformFinalBlock(input, currentPosition, input.Length-currentPosition);
                if (finalBytes == null) {
                    return null;
                } else if (finalBytes.Length > 0) {
                    byte[] finalOutput = new byte[output.Length + finalBytes.Length];
                    Buffer.BlockCopy(output, 0, finalOutput, 0, output.Length);
                    Buffer.BlockCopy(finalBytes, 0, finalOutput, output.Length, finalBytes.Length);
                    output = finalOutput;
                }
            }

            return output;
        }
开发者ID:juhovh,项目名称:AaltoTLS,代码行数:46,代码来源:RecordHandler.cs

示例8: CheckECBRoundtrip

        public void CheckECBRoundtrip(ICryptoTransform encryptor, ICryptoTransform decryptor, 
					   byte[] plaintext, byte[] expected)
        {
            byte[] ciphertext = new byte[plaintext.Length];
            encryptor.TransformBlock(plaintext, 0, plaintext.Length, ciphertext, 0);

            Assert.AreEqual (expected, ciphertext, "ECB");

            byte[] roundtrip = new byte[plaintext.Length];
            decryptor.TransformBlock(ciphertext, 0, ciphertext.Length, roundtrip, 0);

            Assert.AreEqual (plaintext, roundtrip, "ECB-rt-len");
        }
开发者ID:symform,项目名称:crimson,代码行数:13,代码来源:AesTest.cs

示例9: EncryptBytes

        private byte[] EncryptBytes(ICryptoTransform encryptor, ContentType contentType, ulong seqNum,
          int frameIndex, byte[] plainBytes)
        {
            byte[] mac;

            if (SecurityParameters.MACAlgorithm != MACAlgorithm.Null)
            {
                byte[] versionAndType = new byte[] { (byte)contentType, m_protocolVersion[0], m_protocolVersion[1] };
                byte[] seqNumBytes = BitConverter.GetBytes(seqNum);
                byte[] messageSize = BitConverter.GetBytes(plainBytes.Length);
                byte[] frameIndexBytes = BitConverter.GetBytes(frameIndex);

                m_encryptionHMAC.Initialize();
                m_encryptionHMAC.TransformBlock(seqNumBytes, 0, seqNumBytes.Length, seqNumBytes, 0);
                m_encryptionHMAC.TransformBlock(versionAndType, 0, versionAndType.Length, versionAndType, 0);
                m_encryptionHMAC.TransformBlock(messageSize, 0, messageSize.Length, messageSize, 0);
                m_encryptionHMAC.TransformBlock(frameIndexBytes, 0, frameIndexBytes.Length, frameIndexBytes, 0);
                m_encryptionHMAC.TransformFinalBlock(plainBytes, 0, plainBytes.Length);
                mac = m_encryptionHMAC.Hash;
            }
            else
            {
                mac = new byte[0];
            }

            int length = plainBytes.Length + SecurityParameters.MACLength;
            byte padding = 0;

            if (SecurityParameters.BulkCipherAlgorithm != BulkCipherAlgorithm.Null)
            {
                padding = (byte)((encryptor.OutputBlockSize -
                                        (plainBytes.Length + SecurityParameters.MACLength + 1) % encryptor.OutputBlockSize) %
                                       encryptor.OutputBlockSize);

                length += padding + 1;
            }

            byte[] cipherBytes = new byte[length];

            Buffer.BlockCopy(plainBytes, 0, cipherBytes, 0, plainBytes.Length);
            Buffer.BlockCopy(mac, 0, cipherBytes, plainBytes.Length, SecurityParameters.MACLength);

            if (SecurityParameters.BulkCipherAlgorithm != BulkCipherAlgorithm.Null)
            {
                for (int i = plainBytes.Length + SecurityParameters.MACLength; i < cipherBytes.Length; i++)
                {
                    cipherBytes[i] = padding;
                }

                encryptor.TransformBlock(cipherBytes, 0, cipherBytes.Length, cipherBytes, 0);
            }

            return cipherBytes;
        }
开发者ID:EugenDueck,项目名称:netmq,代码行数:54,代码来源:RecordLayer.cs

示例10: Collect

 private static void Collect(this List<byte> l, ICryptoTransform transform, Stream input, int count)
 {
     byte[] buffer = new byte[count];
     int numRead = input.Read(buffer, 0, count);
     Assert.Equal(count, numRead);
     byte[] buffer2 = new byte[count];
     int numBytesWritten = transform.TransformBlock(buffer, 0, count, buffer2, 0);
     Array.Resize(ref buffer2, numBytesWritten);
     l.AddRange(buffer2);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:AesCornerTests.cs

示例11: Encrypt

        static void Encrypt(byte[] data, int offset, int len, ICryptoTransform key, byte[] iv, int startCounter, byte[] temp512)
        {
            var buf = temp512;
            var block = startCounter;

            const int numBlocks = 32;

            for (var pos = 0; pos < len; pos += 16 * numBlocks)
            {
                var blocks = numBlocks;
                if (pos + 16 * numBlocks > len)
                    blocks = (len - pos + 15) / 16;

                for (var i = 0; i < blocks; i++)
                {
                    Buffer.BlockCopy(iv, 0, buf, i * 16, 14);
                    buf[i * 16 + 14] = (byte)(block >> 8);
                    buf[i * 16 + 15] = (byte)block;
                    ++block;
                }

                key.TransformBlock(buf, 0, blocks * 16, buf, 0);
                var end = Math.Min(pos + numBlocks * 16, len);
                for (int i = pos, j = 0; i < end; i++, j++)
                {
                    data[offset + i] ^= buf[j];
                }
            }
        }
开发者ID:kraaden,项目名称:npgsql,代码行数:29,代码来源:GaloisCounterMode.cs

示例12: TransformBlocksFast

 void TransformBlocksFast(byte[] bufIn, byte[] bufOut, ICryptoTransform transformer)
 {
     for (int i = 0; i < bufIn.Length / BlockSize; i++)
         transformer.TransformBlock(bufIn, i * BlockSize, BlockSize, bufOut, i * BlockSize);
 }
开发者ID:fubar-coder,项目名称:cryptrans,代码行数:5,代码来源:AES.cs

示例13: GenericTransform

 internal static byte[] GenericTransform(ICryptoTransform transform,
                                     byte[] data)
 {
     List<byte> byteList = new List<byte>();
       byte[] outputBytes;
       int inputLength = data.Length;
       int inputBlockSize = transform.InputBlockSize;
       if (typeof(FromBase64Transform).IsInstanceOfType(transform)) {
     // workaround for apparent bug where FromBase64Transform.InputBlockSize
     // returns 1 when it should return 4
     inputBlockSize = 4;
       }
       int inputOffset = 0;
       outputBytes = new byte[transform.OutputBlockSize];
       if (!transform.CanTransformMultipleBlocks) {
     while (inputLength - inputOffset > inputBlockSize) {
       transform.TransformBlock(data, inputOffset, inputBlockSize,
     outputBytes, 0);
       byteList.AddRange(outputBytes);
       inputOffset += inputBlockSize;
     }
       }
       outputBytes = transform.TransformFinalBlock(data, inputOffset,
                                           inputLength - inputOffset);
       byteList.AddRange(outputBytes);
       byte[] result = byteList.ToArray();
       ClearByteList(byteList);
       return result;
 }
开发者ID:dlech,项目名称:SshAgentLib,代码行数:29,代码来源:Util.cs

示例14: encrypt

 public void encrypt(byte[] plainData, byte[] destination)
 {
     tfEncryptor = tf.CreateEncryptor(tf.Key,tf.IV);
     for (int i = 0;i<plainData.Length/16;i++)
         tfEncryptor.TransformBlock(plainData,i*16,16,destination,i*16);
 }
开发者ID:hdneo,项目名称:mxo-hd,代码行数:6,代码来源:MxoTwofish.cs

示例15: decrypt

 public void decrypt(byte[] criptedData, byte[] destination)
 {
     tfDecryptor = tf.CreateDecryptor(tf.Key,tf.IV);
     for (int i = 0;i<criptedData.Length/16;i++)
         tfDecryptor.TransformBlock(criptedData,i*16,16,destination,i*16);
 }
开发者ID:hdneo,项目名称:mxo-hd,代码行数:6,代码来源:MxoTwofish.cs


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