{"id":5054,"date":"2022-06-02T02:38:51","date_gmt":"2022-06-01T17:38:51","guid":{"rendered":"https:\/\/okamurax.com\/?p=5054"},"modified":"2022-06-02T05:38:01","modified_gmt":"2022-06-01T20:38:01","slug":"c-aes-%e6%96%87%e5%ad%97%e5%88%97%e6%9a%97%e5%8f%b7%e5%8c%96","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=5054","title":{"rendered":"C# \u6587\u5b57\u5217\u3092AES\u6697\u53f7\u5316"},"content":{"rendered":"<pre class=\"lang:c# decode:true \">        private string Encrypt(string plainText)\r\n        {\r\n            \/\/ \u534a\u89d216\u6587\u5b57(128bit)\u300124\u6587\u5b57(192bit)\u300132\u6587\u5b57(256bit)\u304b\u3089\u9078\u3076\u3002\r\n            byte[] key = Encoding.UTF8.GetBytes(@\"u5vwged9ky6y6vii\");\r\n\r\n            \/\/ Block Size\u3068\u540c\u3058\u306b\u3059\u308b\u3002\u534a\u89d216\u6587\u5b57(128bit)\r\n            byte[] iv = Encoding.UTF8.GetBytes(@\"8knshgxqy4uf89gq\"); \r\n\r\n            byte[] byteValue = Encoding.UTF8.GetBytes(plainText);\r\n            var byteLength = byteValue.Length;\r\n\r\n            using (var aes = Aes.Create())\r\n            using (var encryptor = aes.CreateEncryptor(key, iv))\r\n            {\r\n                var encryptValue = encryptor.TransformFinalBlock(byteValue, 0, byteLength);\r\n                var base64Value = Convert.ToBase64String(encryptValue);\r\n                return base64Value;\r\n            }\r\n        }\r\n\r\n        public static string Decrypt(string encryptText)\r\n        {\r\n            byte[] key = Encoding.UTF8.GetBytes(@\"u5vwged9ky6y6vii\");\r\n            byte[] iv = Encoding.UTF8.GetBytes(@\"8knshgxqy4uf89gq\");\r\n\r\n            var byteValue = Convert.FromBase64String(encryptText);\r\n            var byteLength = byteValue.Length;\r\n\r\n            using (var aes = Aes.Create())\r\n            using (var decryptor = aes.CreateDecryptor(key, iv))\r\n            {\r\n                var decryptValue = decryptor.TransformFinalBlock(byteValue, 0, byteLength);\r\n                var stringValue = Encoding.UTF8.GetString(decryptValue);\r\n                return stringValue;\r\n            }\r\n        }<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>private string Encrypt(string plainText) { \/\/ \u534a\u89d216\u6587\u5b57(128bit)\u300124\u6587\u5b57(192bit)\u300132\u6587\u5b57(256bit)\u304b\u3089\u9078\u3076\u3002 byte[] key = Encod &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=5054\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;C# \u6587\u5b57\u5217\u3092AES\u6697\u53f7\u5316&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9],"class_list":["post-5054","post","type-post","status-publish","format-standard","hentry","category-1","tag-c-net"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/5054","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5054"}],"version-history":[{"count":3,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/5054\/revisions"}],"predecessor-version":[{"id":5059,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/5054\/revisions\/5059"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}