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


C# ICryptoTransform类代码示例

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


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

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

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

示例7: SetUp

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

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

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

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

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

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

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

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

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


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