{"id":34,"date":"2011-04-03T21:42:36","date_gmt":"2011-04-03T17:42:36","guid":{"rendered":"http:\/\/infobs.athn.ru\/?p=34"},"modified":"2011-04-03T21:42:36","modified_gmt":"2011-04-03T17:42:36","slug":"shifrovanie-stroki-ili-massiva-bayt-c","status":"publish","type":"post","link":"https:\/\/infobase.athn.ru\/program\/2011\/04\/shifrovanie-stroki-ili-massiva-bayt-c\/","title":{"rendered":"\u0428\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0431\u0430\u0439\u0442, C#"},"content":{"rendered":"<p>\u0412 MSDN \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u0430\u043a \u0437\u0430\u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u0442\u044c \u0446\u0435\u043b\u044b\u0439 \u0444\u0430\u0439\u043b. \u041d\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u0437\u0430\u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0431\u0430\u0439\u0442. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u043e\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0431\u0435\u043b.<\/p>\n<p><!--more--><\/p>\n<pre>\nusing System;\nusing System.IO;\nusing System.Text;\nusing System.Security.Cryptography;\n \nnamespace RSDN\n{\n    public class Crypt\n    {\n        public static byte[] Encrypt(byte[] data,string password)\n        {\n            SymmetricAlgorithm sa = Rijndael.Create();\n            ICryptoTransform ct = sa.CreateEncryptor(\n                (new PasswordDeriveBytes(password,null)).GetBytes(16),\n                new byte[16]);\n \n            MemoryStream ms = new MemoryStream();\n            CryptoStream cs = new CryptoStream(ms,ct,CryptoStreamMode.Write);\n \n            cs.Write(data,0,data.Length);\n            cs.FlushFinalBlock();\n \n            return ms.ToArray();\n        }\n \n        public static string Encrypt(string data,string password)\n        {\n            return Convert.ToBase64String(Encrypt(Encoding.UTF8.GetBytes(data),password));\n        }\n \n        static public byte[] Decrypt(byte[] data,string password)\n        {\n            BinaryReader br = new BinaryReader(InternalDecrypt(data,password));\n            return br.ReadBytes((int)br.BaseStream.Length);\n        }\n \n        static public string Decrypt(string data,string password)\n        {\n            CryptoStream cs = InternalDecrypt(Convert.FromBase64String(data),password);\n            StreamReader sr = new StreamReader(cs);\n            return sr.ReadToEnd();\n        }\n \n        static CryptoStream InternalDecrypt(byte[] data,string password)\n        {\n            SymmetricAlgorithm sa = Rijndael.Create();\n            ICryptoTransform ct = sa.CreateDecryptor(\n                (new PasswordDeriveBytes(password,null)).GetBytes(16),\n                new byte[16]);\n \n            MemoryStream ms = new MemoryStream(data);\n            return new CryptoStream(ms,ct,CryptoStreamMode.Read);\n        }\n    }\n}<\/pre>\n<p>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a: http:\/\/www.codelab.ru\/task\/crypt_anything\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 MSDN \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u0430\u043a \u0437\u0430\u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u0442\u044c \u0446\u0435\u043b\u044b\u0439 \u0444\u0430\u0439\u043b. \u041d\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u0437\u0430\u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0431\u0430\u0439\u0442. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u043e\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0431\u0435\u043b.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[219,281,317],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-csharp","tag-massiv","tag-stroka","tag-shifrovanie"],"_links":{"self":[{"href":"https:\/\/infobase.athn.ru\/program\/wp-json\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/infobase.athn.ru\/program\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/infobase.athn.ru\/program\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/infobase.athn.ru\/program\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/infobase.athn.ru\/program\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":0,"href":"https:\/\/infobase.athn.ru\/program\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"https:\/\/infobase.athn.ru\/program\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/infobase.athn.ru\/program\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/infobase.athn.ru\/program\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}