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


C# ICryptoTransform.TransformFinalBlock方法代码示例

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


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

示例1: EncryptDecryptAndDispose

        private static void EncryptDecryptAndDispose(ICryptoTransform crypto, ICryptoTransform decrypto, byte[] data)
        {
            var encryptedData = crypto.TransformFinalBlock(data, 0, data.Length);
            var decryptedData = decrypto.TransformFinalBlock(encryptedData, 0, encryptedData.Length);

            // NOTE: no need to check if they are equal
            //if (!decryptedData.AllEqual(data))
               // throw new InvalidProgramException();

            crypto.Dispose();
            decrypto.Dispose();
        }
开发者ID:aliostad,项目名称:EncryptionBenchmark,代码行数:12,代码来源:Program.cs

示例2: 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

示例3: SymmetricEncryption

        private BufferChunk SymmetricEncryption(RtpPacket packet,ICryptoTransform crypto)
        {
            BufferChunk payload = packet.Payload;

            byte[] data = crypto.TransformFinalBlock(payload.Buffer, payload.Index, payload.Length);

            return new BufferChunk(data);
        }
开发者ID:psyCHOder,项目名称:conferencexp,代码行数:8,代码来源:EncryptionTransform.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: Decrypt

        /// <summary>
        /// Decrypts the informed string
        /// </summary>
        /// <param name="str">The string that will be decrypted</param>
        /// <returns>The decrypted string</returns>
        public static string Decrypt(string str)
        {
            try
            {
                arrResult = new byte[0];
                arrKey = md5.ComputeHash(utf8.GetBytes(key));

                tripleDES.Key = arrKey;
                tripleDES.Mode = CipherMode.ECB;
                tripleDES.Padding = PaddingMode.PKCS7;

                arrBytes = Convert.FromBase64String(str);
                cryptoTransform = tripleDES.CreateDecryptor();
                arrResult = cryptoTransform.TransformFinalBlock(arrBytes, 0, arrBytes.Length);

                return utf8.GetString(arrResult);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while decrypting: " + e.Message);
                return string.Empty;
            }
        }
开发者ID:adrielcafe,项目名称:CryptoUtil,代码行数:28,代码来源:CryptoUtil.cs

示例6: Encrypt

 private static byte[] Encrypt(ICryptoTransform crypto, byte[] data)
 {
     return crypto.TransformFinalBlock(data, 0, data.Length);
 }
开发者ID:aliostad,项目名称:EncryptionBenchmark,代码行数:4,代码来源:Program.cs

示例7: ComputeHashes

        /// <summary>
        /// Does the actual work of pulling the filestreams in
        /// and passing the blocks into the crytoprovider
        /// </summary>
        /// <param name="filenames">An array of String objects, each containing a filename</param>
        /// <param name="cryptoInterface">An <see cref="ICryptoTransform"/> interface pointing to a cryptoprovider</param>
        /// <param name="blockSize">Size in bytes of the transform block / read buffer</param>
        protected void ComputeHashes(String[] filenames, ICryptoTransform cryptoInterface, int blockSize)
        {
            for (int loop = 0; loop <= filenames.GetUpperBound(0); loop++)
            {
                using (FileStream inputFile = new FileStream(filenames[loop], FileMode.Open, FileAccess.Read))
                {
                    byte[] readBuffer = new byte[(int)blockSize];
                    byte[] copyBuffer;
                    long fileLength = inputFile.Length;
                    int bytesRead = 0;
                    long totalBytesRead = 0;

                    while (totalBytesRead < fileLength)
                    {
                        bytesRead = inputFile.Read(readBuffer, 0, (int)blockSize);
                        if (bytesRead == blockSize) { copyBuffer = readBuffer; }
                        else
                        {
                            copyBuffer = new byte[bytesRead];
                            Array.Copy(readBuffer, copyBuffer, bytesRead);
                        }
                        totalBytesRead += bytesRead;
                        if (totalBytesRead == fileLength && loop == filenames.GetUpperBound(0))
                        {
                            // Last block of the last file
                            cryptoInterface.TransformFinalBlock(copyBuffer, 0, copyBuffer.Length);
                        }
                        else
                        {
                            cryptoInterface.TransformBlock(copyBuffer, 0, copyBuffer.Length, copyBuffer, 0);
                        }
                        // Report progress and
                        // check for cancellation request
                        OnHashBlockProcessed(new HasherEventArgs(HasherEventReportType.ProgressReport,
                                         filenames.Length,
                                         loop + 1,
                                         totalBytesRead,
                                         fileLength));
                        if (this.cancelRequested == true)
                        {
                            throw new OperationCanceledException();
                        }

                    }
                }
            }
            // Report hash computed
            OnHashComputed(new HasherEventArgs(HasherEventReportType.Completed, null, null, null, null));
        }
开发者ID:bendras,项目名称:HashSlinger,代码行数:56,代码来源:StreamHasher.cs

示例8: Decrypt2

 private unsafe UnmanagedArray<byte> Decrypt2(byte[] bytes, ICryptoTransform transform)
 {
     byte[] managedBytes = transform.TransformFinalBlock(bytes, 0, bytes.Length);
     //pin it ASAP. this is a small race condition that is unavoidable due
     //to the way the crypto API's return byte[].
     fixed (byte* dummy = managedBytes)
     {
         try
         {
             UnmanagedByteArray rv = new UnmanagedByteArray(managedBytes.Length);
             for (int i = 0; i < rv.Length; i++)
             {
                 rv[i] = managedBytes[i];
             }
             return rv;
         }
         finally
         {
             SecurityUtil.Clear(managedBytes);
         }
     }
 }
开发者ID:elek,项目名称:identityconnectors,代码行数:22,代码来源:Security.cs

示例9: AesDecrypt

 public string AesDecrypt(ICryptoTransform decrypter, string encryptedString)
 {
     var inBytes = Convert.FromBase64String(encryptedString);
     byte[] outBlock = decrypter.TransformFinalBlock(inBytes, 0, inBytes.Length);
     return Encoding.Unicode.GetString(outBlock);
 }
开发者ID:tomasking,项目名称:CryptographyDemo,代码行数:6,代码来源:HybridEncryptionDemo.cs

示例10: AesEncrypt

 public string AesEncrypt(ICryptoTransform encryptor, string plainText)
 {
     byte[] inBlock = Encoding.Unicode.GetBytes(plainText);
     byte[] outBlock = encryptor.TransformFinalBlock(inBlock, 0, inBlock.Length);
     return Convert.ToBase64String(outBlock);
 }
开发者ID:tomasking,项目名称:CryptographyDemo,代码行数:6,代码来源:HybridEncryptionDemo.cs

示例11: Encrypt

 public static byte[] Encrypt(ICryptoTransform transform, byte[] buffer)
 {
     return transform.TransformFinalBlock(buffer, 0, buffer.Length);
 }
开发者ID:codebutler,项目名称:meshwork,代码行数:4,代码来源:Encryption.cs

示例12: smethod_4

 public static GStruct2 smethod_4(ICryptoTransform icryptoTransform_1, byte[] byte_0)
 {
     GStruct2 result;
     byte_0 = icryptoTransform_1.TransformFinalBlock(byte_0, 0, byte_0.Length);
     MemoryStream memoryStream_0 = new MemoryStream(byte_0);
     BinaryReader binaryReader_0 = new BinaryReader(memoryStream_0);
     if (binaryReader_0.ReadBoolean())
     {
         int num = binaryReader_0.ReadInt32();
         DeflateStream deflateStream = new DeflateStream(memoryStream_0, CompressionMode.Decompress, false);
         byte[] array = new byte[num - 1 + 1];
         deflateStream.Read(array, 0, array.Length);
         deflateStream.Close();
         memoryStream_0 = new MemoryStream(array);
         binaryReader_0 = new BinaryReader(memoryStream_0);
     }
     GStruct2 gStruct = default(GStruct2);
     gStruct.byte_0 = binaryReader_0.ReadByte();
     gStruct.byte_1 = binaryReader_0.ReadByte();
     List<object> list_0 = new List<object>();
     if (binaryReader_0.ReadBoolean())
     {
         gStruct.guid_0 = new Guid(binaryReader_0.ReadBytes(16));
     }
     while (memoryStream_0.Position != memoryStream_0.Length)
     {
         switch (binaryReader_0.ReadByte())
         {
             case 0:
                 list_0.Add(binaryReader_0.ReadBoolean());
                 break;
             case 1:
                 list_0.Add(binaryReader_0.ReadByte());
                 break;
             case 2:
                 list_0.Add(binaryReader_0.ReadBytes(binaryReader_0.ReadInt32()));
                 break;
             case 3:
                 list_0.Add(binaryReader_0.ReadChar());
                 break;
             case 4:
                 list_0.Add(binaryReader_0.ReadString().ToCharArray());
                 break;
             case 5:
                 list_0.Add(binaryReader_0.ReadDecimal());
                 break;
             case 6:
                 list_0.Add(binaryReader_0.ReadDouble());
                 break;
             case 7:
                 list_0.Add(binaryReader_0.ReadInt32());
                 break;
             case 8:
                 list_0.Add(binaryReader_0.ReadInt64());
                 break;
             case 9:
                 list_0.Add(binaryReader_0.ReadSByte());
                 break;
             case 10:
                 list_0.Add(binaryReader_0.ReadInt16());
                 break;
             case 11:
                 list_0.Add(binaryReader_0.ReadSingle());
                 break;
             case 12:
                 list_0.Add(binaryReader_0.ReadString());
                 break;
             case 13:
                 list_0.Add(binaryReader_0.ReadUInt32());
                 break;
             case 14:
                 list_0.Add(binaryReader_0.ReadUInt64());
                 break;
             case 15:
                 list_0.Add(binaryReader_0.ReadUInt16());
                 break;
             case 16:
                 list_0.Add(DateTime.FromBinary(binaryReader_0.ReadInt64()));
                 break;
             case 17:
                 {
                     string[] array2 = new string[binaryReader_0.ReadInt32() - 1 + 1];
                     int arg_381_0 = 0;
                     int num2 = array2.Length - 1;
                     for (int i = arg_381_0; i <= num2; i++)
                     {
                         array2[i] = binaryReader_0.ReadString();
                     }
                     list_0.Add(array2);
                     break;
                 }
             case 18:
                 {
                     List<object> arg_3D0_0 = list_0;
                     Guid guid = new Guid(binaryReader_0.ReadBytes(16));
                     arg_3D0_0.Add(guid);
                     break;
                 }
             case 19:
                 {
//.........这里部分代码省略.........
开发者ID:BahNahNah,项目名称:StubDump,代码行数:101,代码来源:NanoCore_1_2_2_5.cs

示例13: EncrypteMessageByAes

 /// <summary>
 /// Encrypt message by AES with given secret key and key size.
 /// </summary>
 /// <param name="encryptor">A symmetric encryptor object with key and IV</param>
 /// <param name="message">Message to be encrypted.</param>
 /// <returns>Message has been encrypted.</returns>
 private static byte[] EncrypteMessageByAes(ICryptoTransform encryptor, byte[] message)
 {
     byte[] encryptedMessage = new byte[16];
     byte[] encryptedBytes = encryptor.TransformFinalBlock(message, 0, message.Length).ToArray();
     for (int i = 0; i < 16; i++)
     {
         encryptedMessage[i] = encryptedBytes[i];
     }
     return encryptedMessage;
 }
开发者ID:LiuXiaotian,项目名称:WindowsProtocolTestSuites,代码行数:16,代码来源:AesCmacCrypto.cs

示例14: 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

示例15: Encrypt2

 private unsafe byte[] Encrypt2(UnmanagedArray<byte> bytes, ICryptoTransform transform)
 {
     byte[] managedBytes = new byte[bytes.Length];
     fixed (byte* dummy = managedBytes)
     {
         try
         {
             SecurityUtil.UnmanagedBytesToManagedBytes(bytes, managedBytes);
             byte[] rv = transform.TransformFinalBlock(managedBytes, 0, managedBytes.Length);
             return rv;
         }
         finally
         {
             SecurityUtil.Clear(managedBytes);
         }
     }
 }
开发者ID:elek,项目名称:identityconnectors,代码行数:17,代码来源:Security.cs


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