{"id":1977,"date":"2018-03-13T18:12:02","date_gmt":"2018-03-14T00:12:02","guid":{"rendered":"https:\/\/www.lastdragon.net\/?p=1977"},"modified":"2018-03-13T18:39:56","modified_gmt":"2018-03-14T00:39:56","slug":"codigo-de-cifrado-con-aes-en-c","status":"publish","type":"post","link":"https:\/\/www.lastdragon.net\/?p=1977","title":{"rendered":"C\u00f3digo de Cifrado con AES en C#"},"content":{"rendered":"<blockquote><p>Cifra y decifra una cadena de texto antes de mostrarse en la pantalla<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/w2y2Rs_OJC8\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen><\/iframe><\/p>\n<p>using System;<br \/>\nusing System.Security.Cryptography;<\/p>\n<p>class ProgramaCifrador<br \/>\n{<\/p>\n<p>AesCryptoServiceProvider Cifrador;<\/p>\n<p>public void IniciarAES(string Llave){<\/p>\n<p>Rfc2898DeriveBytes llaveSimetrica = new Rfc2898DeriveBytes(Llave, 20);<\/p>\n<p>Cifrador = new AesCryptoServiceProvider();<br \/>\nCifrador.BlockSize = 128;<br \/>\nCifrador.KeySize = 256;<br \/>\nCifrador.GenerateIV();<br \/>\nCifrador.Key = llaveSimetrica.GetBytes(24);<br \/>\nCifrador.Mode = CipherMode.CBC;<br \/>\nCifrador.Padding = PaddingMode.PKCS7;<br \/>\n}<\/p>\n<p>public String Cifrar (String cadena) {<\/p>\n<p>ICryptoTransform transforma = Cifrador.CreateEncryptor();<br \/>\nbyte[] CadenaCifrada = transforma.TransformFinalBlock(System.Text.ASCIIEncoding.ASCII.GetBytes(cadena),0,cadena.Length);<br \/>\nreturn Convert.ToBase64String(CadenaCifrada);<br \/>\n}<\/p>\n<p>public string Decifrar(string Cadena){<\/p>\n<p>ICryptoTransform transforma = Cifrador.CreateDecryptor();<br \/>\nbyte[] Base64 = Convert.FromBase64String(Cadena);<br \/>\nbyte[] Texto = transforma.TransformFinalBlock(Base64,0,Base64.Length);<br \/>\nreturn System.Text.ASCIIEncoding.ASCII.GetString(Texto);<br \/>\n}<\/p>\n<p>public static void Main(string[] args)<br \/>\n{<\/p>\n<p>ProgramaCifrador x = new ProgramaCifrador();<br \/>\nx.IniciarAES (&#8220;LlaveSimetrica&#8221;);<\/p>\n<p>Console.Write(x.Decifrar(x.Cifrar(&#8220;Este texto fue cifrado y decifrado antes de ser mostrado en tu pantalla&#8221;) ));<br \/>\nConsole.ReadKey(true);<br \/>\n}<br \/>\n}<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Cifra y decifra una cadena de texto antes de mostrarse en la pantalla using System; using System.Security.Cryptography; class ProgramaCifrador { AesCryptoServiceProvider Cifrador; public void IniciarAES(string Llave){ Rfc2898DeriveBytes llaveSimetrica = new Rfc2898DeriveBytes(Llave, 20); Cifrador = new AesCryptoServiceProvider(); Cifrador.BlockSize = 128; Cifrador.KeySize = 256; Cifrador.GenerateIV(); Cifrador.Key = llaveSimetrica.GetBytes(24); Cifrador.Mode = CipherMode.CBC; Cifrador.Padding = PaddingMode.PKCS7; } public String&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1633,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1977","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programacion"],"_links":{"self":[{"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/posts\/1977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1977"}],"version-history":[{"count":4,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/posts\/1977\/revisions"}],"predecessor-version":[{"id":1981,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/posts\/1977\/revisions\/1981"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=\/wp\/v2\/media\/1633"}],"wp:attachment":[{"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lastdragon.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}