{"id":50735,"date":"2024-12-03T14:36:18","date_gmt":"2024-12-03T06:36:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/50735\/"},"modified":"2024-12-03T14:36:18","modified_gmt":"2024-12-03T06:36:18","slug":"python-rsa-%e5%8a%a0%e5%af%86%e5%a6%82%e4%bd%95%e8%bd%ac%e6%8d%a2%e4%b8%ba-c-%e4%bb%a3%e7%a0%81%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/50735\/","title":{"rendered":"Python RSA \u52a0\u5bc6\u5982\u4f55\u8f6c\u6362\u4e3a C# \u4ee3\u7801\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python RSA \u52a0\u5bc6\u5982\u4f55\u8f6c\u6362\u4e3a C# \u4ee3\u7801\uff1f<\/h1>\n<p>\u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPython RSA \u52a0\u5bc6\u5982\u4f55\u8f6c\u6362\u4e3a C# \u4ee3\u7801\uff1f\u300b<\/span>\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241126\/17326222796745b7c769805.jpg\" class=\"aligncenter\" title=\"Python RSA \u52a0\u5bc6\u5982\u4f55\u8f6c\u6362\u4e3a C# \u4ee3\u7801\uff1f\u63d2\u56fe\" alt=\"Python RSA \u52a0\u5bc6\u5982\u4f55\u8f6c\u6362\u4e3a C# \u4ee3\u7801\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>python rsa \u52a0\u5bc6\u8f6c\u6362\u6210 c# \u4ee3\u7801<\/strong><\/p>\n<p>\u8981\u5728 .net core 3.1 \u4e2d\u4f7f\u7528 rsa \u52a0\u5bc6\uff0c\u53ef\u4ee5\u5229\u7528 python \u63d0\u4f9b\u7684\u4ee3\u7801\u6765\u8f6c\u6362\u3002\u5c06 python \u4e2d rsa \u7684\u76f8\u5173\u51fd\u6570\u548c\u5e93\u8f6c\u6362\u6210 c# \u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p><strong>\u83b7\u53d6 rsa \u52a0\u5bc6<\/strong><\/p>\n<pre>public static string GetRsaEncrypt(string rsaKey, string txt)\n{\n    \/\/ \u516c\u94a5\u5927\u7d20\u6570\n    BigInteger biE = BigInteger.Parse(rsaKey, NumberStyles.HexNumber);\n\n    \/\/ \u5927\u6574\u6570 N\n    BigInteger biN = BigInteger.Parse(\"10001\", NumberStyles.HexNumber);\n\n    byte[] publicKeyByte2 = biE.ToByteArray().Reverse().ToArray();\n    byte[] exponentByte2 = biN.ToByteArray().Reverse().ToArray();\n\n    using (var RSA = new RSACryptoServiceProvider())\n    {\n        var RSAKeyInfo = new RSAParameters\n        {\n            Modulus = publicKeyByte2,\n            Exponent = exponentByte2\n        };\n\n        RSA.ImportParameters(RSAKeyInfo);\n        byte[] passwordByte = Encoding.UTF8.GetBytes(txt);\n        var encryptResult = RSA.Encrypt(passwordByte, RSAEncryptionPadding.Pkcs1);\n        string encrypted = BitConverter.ToString(encryptResult).Replace(\"-\", \"\");\n        return encrypted;\n    }\n}<\/pre>\n<p>\u4f7f\u7528\u8be5\u65b9\u6cd5\u5373\u53ef\u5c06 python \u4e2d rsa \u52a0\u5bc6\u7684\u4ee3\u7801\u8f6c\u6362\u4e3a c# \u4ee3\u7801\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aPython RSA \u52a0\u5bc6\u5982\u4f55\u8f6c\u6362\u4e3a C# \u4ee3\u7801\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python RSA \u52a0\u5bc6\u5982\u4f55\u8f6c\u6362\u4e3a C# \u4ee3\u7801\uff1f \u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587\u300aPython RSA \u52a0\u5bc6\u5982\u4f55\u8f6c\u6362\u4e3a C# \u4ee3\u7801\uff1f\u300b\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0\u6587\u7ae0\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01 python rsa \u52a0\u5bc6\u8f6c\u6362\u6210 c# \u4ee3\u7801 \u8981\u5728 .net core 3.1 \u4e2d\u4f7f\u7528 rsa \u52a0\u5bc6\uff0c\u53ef\u4ee5\u5229\u7528 python \u63d0\u4f9b\u7684\u4ee3\u7801\u6765\u8f6c\u6362\u3002\u5c06 python \u4e2d rsa \u7684\u76f8\u5173\u51fd\u6570\u548c\u5e93\u8f6c\u6362\u6210 c# \u4ee3\u7801\u5982\u4e0b\uff1a \u83b7\u53d6 rsa \u52a0\u5bc6 public static string GetRsaEncrypt(string rsaKey, string txt) { \/\/ \u516c\u94a5\u5927\u7d20\u6570 BigInteger biE = BigInteger.Parse(rsaKey, NumberStyles.HexNumber); \/\/ \u5927\u6574\u6570 N BigInteger biN = BigInteger.Parse(&#8220;10001&#8221;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-50735","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=50735"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50735\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=50735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=50735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=50735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}