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

C# ICryptoTransform类代码示例

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

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



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

示例1: CryptoStream

		public CryptoStream (Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
		{
			if ((mode == CryptoStreamMode.Read) && (!stream.CanRead)) {
				throw new ArgumentException (
					Locale.GetText ("Can't read on stream"));
			}
			if ((mode == CryptoStreamMode.Write) && (!stream.CanWrite)) {
				throw new ArgumentException (
					Locale.GetText ("Can't write on stream"));
			}
			_stream = stream;
			_transform = transform;
			_mode = mode;
			_disposed = false;
			if (transform != null) {
				if (mode == CryptoStreamMode.Read) {
					_currentBlock = new byte [transform.InputBlockSize];
					_workingBlock = new byte [transform.InputBlockSize];
				}
				else if (mode == CryptoStreamMode.Write) {
					_currentBlock = new byte [transform.OutputBlockSize];
					_workingBlock = new byte [transform.OutputBlockSize];
				}
			}
		}
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:25,代码来源:CryptoStream.cs


示例2: PerformRandomizedTest

        private static byte[] PerformRandomizedTest(ICryptoTransform expectedTransform, ICryptoTransform actualTransform,
                                                    byte[] vector)
        {
            using (var msExpected = new MemoryStream())
            using (var msActual = new MemoryStream())
            {
                using (var csExpected = new CryptoStream(msExpected, expectedTransform, CryptoStreamMode.Write))
                using (var csActual = new CryptoStream(msActual, actualTransform, CryptoStreamMode.Write))
                {
                    byte[] bufferToTransform = vector;
                    if (bufferToTransform == null)
                    {
                        int randomBytesToGenerate = _WeakRandom.Next(0, MaxEncryptedSizeInBytes);
                        bufferToTransform = new byte[randomBytesToGenerate];
                        _WeakRandom.NextBytes(bufferToTransform);
                    }
                    csExpected.Write(bufferToTransform, 0, bufferToTransform.Length);
                    csActual.Write(bufferToTransform, 0, bufferToTransform.Length);
                }

                byte[] expectedTransformResult = msExpected.ToArray();
                byte[] actualTransformResult = msActual.ToArray();

                ByteUtilities.AssertBytesEqual(expectedTransformResult, actualTransformResult);

                return expectedTransformResult;
            }
        }
开发者ID:hartsock,项目名称:AES-Illustrated,代码行数:28,代码来源:RandomizedCapiTests.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: InteractiveCryptoStream

        public InteractiveCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode, int bufferSizeInBlocks)
            : base(stream)
        {
            if (bufferSizeInBlocks < 0)
            {
                throw new ArgumentOutOfRangeException("bufferSizeInBlocks", bufferSizeInBlocks, "BufferSize can't be less than 0");
            }

            if (bufferSizeInBlocks > 255)
            {
                bufferSizeInBlocks = 255;
            }

            this.mode = mode;

            this.transform = transform;

            this.writeBuffer = new byte[2 + transform.InputBlockSize * bufferSizeInBlocks];
            this.writeBlockBuffer = new byte[transform.OutputBlockSize];

            this.readPreBuffer = new byte[transform.OutputBlockSize * 5];
            this.readBuffer = new byte[transform.InputBlockSize * 5];

            this.writeBufferCount = 2;
            this.readBufferCount = 0;
            this.readBufferIndex = 0;
        }
开发者ID:Refactoring,项目名称:Platform,代码行数:27,代码来源:InteractiveCryptoStream.cs


示例5: NoPaddingTransformWrapper

        public NoPaddingTransformWrapper(ICryptoTransform symmetricAlgoTransform)
        {
            if (symmetricAlgoTransform == null)
                throw new ArgumentNullException("symmetricAlgoTransform");

            m_Transform = symmetricAlgoTransform;
        }
开发者ID:anders0913,项目名称:TeraDataTools,代码行数:7,代码来源:NoPaddingTransformWrapper.cs


示例6: Process

            /// <summary>
            /// Process the data with CryptoStream
            /// </summary>
            protected byte[] Process(byte[] data, int startIndex, int count, ICryptoTransform cryptor)
            {
                //
                // the memory stream granularity must match the block size
                // of the current cryptographic operation
                //
                int capacity = count;
                int mod = count % algorithm.BlockSize;
                if (mod > 0)
                {
                    capacity += (algorithm.BlockSize - mod);
                }

                MemoryStream memoryStream = new MemoryStream(capacity);

                CryptoStream cryptoStream = new CryptoStream(
                    memoryStream,
                    cryptor,
                    CryptoStreamMode.Write);

                cryptoStream.Write(data, startIndex, count);
                cryptoStream.FlushFinalBlock();

                cryptoStream.Close();
                cryptoStream = null;

                cryptor.Dispose();
                cryptor = null;

                return memoryStream.ToArray();
            }
开发者ID:ECain,项目名称:MissionPlanner,代码行数:34,代码来源:Crypto.cs


示例7: ExecuteCryptoServiceProvider

        protected static byte[] ExecuteCryptoServiceProvider(byte[] data, ICryptoTransform cryptoTransform)
        {
            byte[] inArray;
            using (var memoryStream = new MemoryStream())
            {
                using (var cryptoStream = new CryptoStream(memoryStream,
                    cryptoTransform, CryptoStreamMode.Write))
                {
                    try
                    {
                        cryptoStream.Write(data, 0, data.Length);
                        cryptoStream.FlushFinalBlock();
                    }
                    catch (Exception ex)
                    {
                        throw new CustomException<CryptoServiceExceptionArgs>(
                            new CryptoServiceExceptionArgs("Error while writing encrypted data to the stream: \n" +
                                                           ex.Message));
                    }
                    finally
                    {
                        cryptoStream.Dispose();
                    }
                }

                inArray = memoryStream.ToArray();
            }

            return inArray;
        }
开发者ID:francis04j,项目名称:LayeredArchitecture,代码行数:30,代码来源:SymmetricEncryptionProviderBase.cs


示例8: AuthenticationHelper

 public AuthenticationHelper()
 {
     var rm = new RijndaelManaged();
     encryptor = rm.CreateEncryptor(key, vector);
     decryptor = rm.CreateDecryptor(key, vector);
     encoder = new UTF8Encoding();
 }
开发者ID:mattycare,项目名称:ReVersion,代码行数:7,代码来源:AuthenticationHelper.cs


示例9: AesEncryption

 public AesEncryption(byte[] Key, byte[] Vector)
 {
     RijndaelManaged rijndaelManaged = new RijndaelManaged();
     this.EncryptorTransform = rijndaelManaged.CreateEncryptor(Key, Vector);
     this.DecryptorTransform = rijndaelManaged.CreateDecryptor(Key, Vector);
     this.UTFEncoder = new UTF8Encoding();
 }
开发者ID:PrivateOrganizationC,项目名称:Primary,代码行数:7,代码来源:AesEncryption.cs


示例10: EncryptionHelper

 // Methods
 public EncryptionHelper()
 {
     RijndaelManaged managed = new RijndaelManaged();
     this.EncryptorTransform = managed.CreateEncryptor(this.Key, this.Vector);
     this.DecryptorTransform = managed.CreateDecryptor(this.Key, this.Vector);
     this.UTFEncoder = new UTF8Encoding();
 }
开发者ID:Alchemy86,项目名称:DAS-Desktop,代码行数:8,代码来源:EncryptionHelper.cs


示例11: SetUp

 public void SetUp()
 {
     using ( AesCryptoServiceProvider aesAlg = new AesCryptoServiceProvider() ) {
         m_Encryptor = aesAlg.CreateEncryptor();
         m_Decryptor = aesAlg.CreateDecryptor();
     }
 }
开发者ID:overmind900,项目名称:Utilities,代码行数:7,代码来源:TestCryptography.cs


示例12: SimplerAES

 public SimplerAES()
 {
     RijndaelManaged rm = new RijndaelManaged();
     encryptor = rm.CreateEncryptor(key, vector);
     decryptor = rm.CreateDecryptor(key, vector);
     encoder = new UTF8Encoding();
 }
开发者ID:DocTonza,项目名称:diplomski,代码行数:7,代码来源:simplerAES.cs


示例13: AesEncryption

 public AesEncryption(byte[] key, byte[] vector)
 {
     var rm = new RijndaelManaged();
     _encryptor = rm.CreateEncryptor(key, vector);
     _decryptor = rm.CreateDecryptor(key, vector);
     _encoder = new UTF8Encoding();
 }
开发者ID:cityindex-attic,项目名称:ciapi-oauth2-service,代码行数:7,代码来源:AesEncryption.cs


示例14: AesDecoderStream

        public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
        {
            mStream = input;
            mLimit = limit;

            // The 7z AES encoder/decoder classes do not perform padding, instead they require the input stream to provide a multiple of 16 bytes.
            // If the exception below is thrown this means the 7z file is either corrupt or a newer 7z version has been published and we haven't updated yet.
            if (((uint)input.Length & 15) != 0)
                throw new NotSupportedException("7z requires AES streams to be properly padded.");

            int numCyclesPower;
            byte[] salt, seed;
            Init(info, out numCyclesPower, out salt, out seed);

            byte[] password = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword());
            byte[] key = InitKey(numCyclesPower, salt, password);

            using (var aes = Aes.Create())
            {
                aes.Mode = CipherMode.CBC;
                aes.Padding = PaddingMode.None;
                mDecoder = aes.CreateDecryptor(key, seed);
            }

            mBuffer = new byte[4 << 10];
        }
开发者ID:modulexcite,项目名称:managed-lzma,代码行数:26,代码来源:AesDecoderStream.cs


示例15: Init

        public static void Init(GraphicsDevice g, SpriteBatch s, ContentManager c)
        {
            graphics = g;
            spriteBatch = s;
            content = c;
            font = content.Load<SpriteFont>("font\\CommonFont");

            Random rand = new Random(13562538);
            AesManaged aes = new AesManaged();
            byte[] b_key = new byte[32];
            byte[] b_iv = new byte[16];
            rand.NextBytes(b_key);
            rand.NextBytes(b_iv);
            aes.Key = b_key;
            aes.IV = b_iv;
            decryptor = aes.CreateDecryptor();

            state = State.Free;
            waitall = false;
            sleepTime = TimeSpan.Zero;

            charas = new Dictionary<string, TalkChara>();
            t_balloon = content.Load<Texture2D>("img\\face\\balloon");
            t_balloon2 = content.Load<Texture2D>("img\\face\\balloon2");
        }
开发者ID:kuuri,项目名称:tohoSRPG,代码行数:25,代码来源:TalkScene.cs


示例16: ZipAESTransform

		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="key">Password string</param>
		/// <param name="saltBytes">Random bytes, length depends on encryption strength.
		/// 128 bits = 8 bytes, 192 bits = 12 bytes, 256 bits = 16 bytes.</param>
		/// <param name="blockSize">The encryption strength, in bytes eg 16 for 128 bits.</param>
		/// <param name="writeMode">True when creating a zip, false when reading. For the AuthCode.</param>
		///
		public ZipAESTransform(string key, byte[] saltBytes, int blockSize, bool writeMode)
		{

			if (blockSize != 16 && blockSize != 32) // 24 valid for AES but not supported by Winzip
				throw new Exception("Invalid blocksize " + blockSize + ". Must be 16 or 32.");
			if (saltBytes.Length != blockSize / 2)
				throw new Exception("Invalid salt len. Must be " + blockSize / 2 + " for blocksize " + blockSize);
			// initialise the encryption buffer and buffer pos
			_blockSize = blockSize;
			_encryptBuffer = new byte[_blockSize];
			_encrPos = ENCRYPT_BLOCK;

			// Performs the equivalent of derive_key in Dr Brian Gladman's pwd2key.c
			var pdb = new Rfc2898DeriveBytes(key, saltBytes, KEY_ROUNDS);
            var rm = Aes.Create();
			rm.Mode = CipherMode.ECB;           // No feedback from cipher for CTR mode
			_counterNonce = new byte[_blockSize];
			byte[] byteKey1 = pdb.GetBytes(_blockSize);
			byte[] byteKey2 = pdb.GetBytes(_blockSize);
			_encryptor = rm.CreateEncryptor(byteKey1, byteKey2);
			_pwdVerifier = pdb.GetBytes(PWD_VER_LENGTH);
			//
			_hmacsha1 = IncrementalHash.CreateHMAC(HashAlgorithmName.SHA1, byteKey2);
			_writeMode = writeMode;
		}
开发者ID:icsharpcode,项目名称:SharpZipLib,代码行数:34,代码来源:ZipAESTransform.cs


示例17: init

        public override void init(int mode, byte[] key, byte[] iv)
        {
            m_mode = mode;
            m_rijndael = new RijndaelManaged();
            m_rijndael.Mode = CipherMode.CBC;
            m_rijndael.Padding = PaddingMode.None;

            byte[] tmp;
            if (iv.Length > m_ivsize)
            {
                tmp = new byte[m_ivsize];
                Array.Copy(iv, 0, tmp, 0, tmp.Length);
                iv = tmp;
            }
            if (key.Length > m_bsize)
            {
                tmp = new byte[m_bsize];
                Array.Copy(key, 0, tmp, 0, tmp.Length);
                key = tmp;
            }

            try
            {
                m_cipher = (mode == ENCRYPT_MODE
                    ? m_rijndael.CreateEncryptor(key, iv)
                    : m_rijndael.CreateDecryptor(key, iv)
                    );
            }
            catch (Exception)
            {
                m_cipher = null;
            }
        }
开发者ID:x893,项目名称:SharpSSH,代码行数:33,代码来源:AES128CBC.cs


示例18: SimpleAES

 public SimpleAES(byte[] encryptionKey, byte[] encryptionVector)
 {
     var rm = new RijndaelManaged();
     _encryptor = rm.CreateEncryptor(encryptionKey, encryptionVector);
     _decryptor = rm.CreateDecryptor(encryptionKey, encryptionVector);
     _encoder = new UTF8Encoding();
 }
开发者ID:calexander3,项目名称:Damage,代码行数:7,代码来源:SimpleAES.cs


示例19: CryptographyService

 public CryptographyService()
 {
     var rm = new RijndaelManaged();
     _encryptor = rm.CreateEncryptor(Key, Vector);
     _decryptor = rm.CreateDecryptor(Key, Vector);
     _encoder = new UTF8Encoding();
 }
开发者ID:roycornelissen,项目名称:ServiceInsight,代码行数:7,代码来源:CryptographyService.cs


示例20: AnvilEncryptor

 public AnvilEncryptor(byte[] k, byte[] v)
 {
     RijndaelManaged rm = new RijndaelManaged();
     encryptor = rm.CreateEncryptor(k, v);
     decryptor = rm.CreateDecryptor(k, v);
     encoder = new UTF8Encoding();
 }
开发者ID:LCPS,项目名称:LCPS-NwUsers,代码行数:7,代码来源:AnvilEncryptor.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# ICssCheckerContext类代码示例发布时间:2022-05-24
下一篇:
C# ICruiseRequest类代码示例发布时间: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