You are on page 1of 3

Blog do Ronie

Inform aes sobre tecnologia e desenvolvim ento .net

Sobre

Type text to search here...

Pgina Inicial > C#, Criptografia, Visual Studio > Especial Criptografia de dados no C#: AES (Advanced Encryption Standard)

RSS

Twitter

Especial Criptografia de dados no C#: AES (Advanced Encryption Standard)


20, outubro, 2009 Ronie Dias Ir para os comentrios Deixar um comentrio

Recent Posts
Finalmente a verso FINAL do Visual Studio 2010!!! Upload Asp.net: Aumentando o limite de tamanho de arquivos LINQ to Objects OrderBy Lanamento do Visual Studio 2010 ser em abril Web Services Consulta CEP Adicionar Atributo / Propriedade Customizado na Diretiva @ Page no asp.net Lista de Encodings disponveis em System.Text.Encoding.GetEncodings() Contagem regressiva para o lanamento do Visual Studio 2010 POG Programao Orientada a Gambiarras Especial Criptografia de dados no C#: MD5 (Message-Digest algorithm 5)

O Advanced Encryption Standard (AES, ou Padro de Criptografia Avanada, em portugus), tambm conhecido por Rijndael, uma cifra de bloco adotada como padro de criptografia pelo governo dos Estados Unidos. Espera-se que seja utilizado em todo o mundo e analisada extensivamente, assim como foi seu predecessor, o Data Encryption Standard (DES). Atualmente o AES um dos algoritmos mais populares usados para criptografia de chave simtrica. W ikipdia: http://pt.w ikipedia.org/w iki/AES Exemplo de utilizao em c#: 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 IV) 050 051 052 053 054 055 056 057 058 059 060 061 { MemoryStream ms = new MemoryStream(); Rijndael alg = Rijndael.Create(); alg.Key = Key; alg.IV = IV; CryptoStream cs = new CryptoStream(ms, alg.CreateDecryptor(), CryptoStreamMode.Write); cs.Write(cipherData, 0, cipherData.Length); cs.Close(); byte[] decryptedData = ms.ToArray(); return decryptedData; } /// <summary> /// Classe de apoio para criptografia AES (Advanced Encryption Standard (AES)) /// </summary> public static class AES { /// <summary> /// Niveis de criptografia AES /// Criptografia de 128, 192 e 256 Bits. /// </summary> public enum AESCryptographyLevel : int { /// <summary> /// Criptografia AES 128 Bits /// </summary> AES_128 = 128, /// <summary> /// Criptografia AES 192 Bits /// </summary> AES_192 = 192, /// <summary> /// Criptografia AES 256 Bits /// </summary> AES_256 = 256 } #region Private // Encrypt a byte array into a byte array using a key and an IV private static byte[] Encrypt(byte[] clearData, byte[] Key, byte[] IV) { // Create a MemoryStream that is going to accept the encrypted bytes MemoryStream ms = new MemoryStream(); Rijndael alg = Rijndael.Create(); alg.Key = Key; alg.IV = IV; CryptoStream cs = new CryptoStream(ms, alg.CreateEncryptor(), CryptoStreamMode.Write); cs.Write(clearData, 0, clearData.Length); cs.Close(); byte[] encryptedData = ms.ToArray(); return encryptedData; } // Decrypt a byte array into a byte array using a key and an IV private static byte[] Decrypt(byte[] cipherData, byte[] Key, byte[]

Tag Cloud
.net app_globalresources ASP asp.net

atalho C# check-out cms Criptografia

cryptografy C ultureInfo delete desfazer


Diverso Framework 3.5 Framework 4 globalization keybinding lambda c# generic ilist comma localization Microsoft UOLHost mojoportal multi-idioma multi-idiomas MVC opensource PHP poster project resources Shortcuts SQL Server Team Explorer Team Foundation Server TFS tfsdelete undo Visual Basic Visual Studio Visual Studio 2008

Visual Studio 2010 vs2010


WebsiteSpark Windows 7 Work Item

Avaliao do Visual Studio 2008 por 90 dias


Professional Team Suite Team Suite Test Load Agent Team System Team Foundation Server

Categories
asp.net C# Criptografia Encoding Framew ork 4 Gerenciador de Contedo LINQ Open Source Sexta-feira Soluo para SQL Server Team Foundation Server Uncategorized VB.NET Visual Studio W indow s 7

Blogroll
Fix Rss Feed

Downloads Gratuitos
Microsoft Framew ork 3.5 SP1 Silverlight SQL Server Express 2008 Visual Studio 2008 SP1 Visual Studio Express

Visual Studio
converted by Web2PDFConvert.com

062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

#endregion #region Public /// <summary> /// Criptografa string usando Rijndael (128,192,256 Bits). /// </summary> /// <param name="data">string a ser criptografada</param> /// <param name="password">senha de criptografia</param> /// <param name="bits">Nvel de criptografia (128,192,256 bits)</param> /// <returns>string criptografada</returns> public static string Encrypt(string data, string password, AESCryptographyLevel bits) { byte[] clearBytes = Encoding.Unicode.GetBytes(data); PasswordDeriveBytes pdb = new PasswordDeriveBytes(password, new byte[] { 0x00, 0x01, 0x02, 0x1C, 0x1D, 0x1E, 0x03, 0x04, 0x05, 0x0F, 0x20, 0x21, 0xAD, 0xAF, 0xA4 }); if (bits == AESCryptographyLevel.AES_128) { byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(16), pdb.GetBytes(16)); return Convert.ToBase64String(encryptedData); } else if (bits == AESCryptographyLevel.AES_192) { byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(24), pdb.GetBytes(16)); return Convert.ToBase64String(encryptedData); } else if (bits == AESCryptographyLevel.AES_256) { byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(32), pdb.GetBytes(16)); return Convert.ToBase64String(encryptedData); } else { return string.Concat(bits); } } /// <summary> /// Descriptografa string usando Rijndael (128,192,256 Bits). /// </summary> /// <param name="data">string a ser descriptografada</param> /// <param name="password">senha de descriptografia</param> /// <param name="bits">Nvel de descriptografia (128,192,256 bits)</param> /// <returns>string descriptografada</returns> public static string Decrypt(string data, string password, AESCryptographyLevel bits) { byte[] cipherBytes = Convert.FromBase64String(data); PasswordDeriveBytes pdb = new PasswordDeriveBytes(password, new byte[] { 0x00, 0x01, 0x02, 0x1C, 0x1D, 0x1E, 0x03, 0x04, 0x05, 0x0F, 0x20, 0x21, 0xAD, 0xAF, 0xA4 }); if (bits == AESCryptographyLevel.AES_128) { byte[] decryptedData = Decrypt(cipherBytes, pdb.GetBytes(16), pdb.GetBytes(16)); return Encoding.Unicode.GetString(decryptedData); } else if (bits == AESCryptographyLevel.AES_192) { byte[] decryptedData = Decrypt(cipherBytes, pdb.GetBytes(24), pdb.GetBytes(16)); return Encoding.Unicode.GetString(decryptedData); } else if (bits == AESCryptographyLevel.AES_256) { byte[] decryptedData = Decrypt(cipherBytes, pdb.GetBytes(32), pdb.GetBytes(16)); return Encoding.Unicode.GetString(decryptedData); } else { return string.Concat(bits); } } #endregion

Visual Studio 2010 RC


Microsoft .NET Framew ork 4 RC Visual Studio 2010 Ultimate RC Visual Studio Team System 2010 Team Foundation Server RC

Archives
abril 2010 fevereiro 2010 janeiro 2010 novembro 2009 outubro 2009 setembro 2009 abril 2009

Meta
Registrar-se Login

Download do exemplo em c#: ExemploAES


At o prximo post! Share and Enjoy:

C #, C riptografia, Visual Studio

aes, C #, C riptografia, cryptografy

Deixar um comentrio

Trackback

Track back s (0)

Com entrios (0)

converted by Web2PDFConvert.com

Nenhum comentrio ainda.

Nome (obrigatrio) E-Mail (no ser publicado) (obrigatrio) Website

Inscrever no feed de comentrios

Enviar comentrio (C trl+Enter)

Notify me of follow up comments via e-mail Especial Criptografia de dados no C#: MD5 (Message-Digest algorithm 5) Especial Criptografia de dados no C#: 3DES (Triple Data Encryption Standard)
Direitos reservados 2009-2010 Blog do Ronie Tema criado por NeoEase. Validar XHTML 1.1 e C SS 3. Topo

converted by Web2PDFConvert.com

You might also like