{"id":331,"date":"2023-02-25T06:44:18","date_gmt":"2023-02-24T22:44:18","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=331"},"modified":"2023-04-30T14:51:32","modified_gmt":"2023-04-30T06:51:32","slug":"principles-and-methods-of-rsa-encryption-decryption-signature-and-verification","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/principles-and-methods-of-rsa-encryption-decryption-signature-and-verification\/","title":{"rendered":"RSA\u52a0\u5bc6\u3001\u89e3\u5bc6\u3001\u7b7e\u540d\u3001\u9a8c\u7b7e\u7684\u539f\u7406\u53ca\u65b9\u6cd5"},"content":{"rendered":"<h2>RSA\u52a0\u5bc6\u7b80\u4ecb<\/h2>\n<p>RSA\u52a0\u5bc6\u662f\u4e00\u79cd\u975e\u5bf9\u79f0\u52a0\u5bc6\u3002\u53ef\u4ee5\u5728\u4e0d\u76f4\u63a5\u4f20\u9012\u5bc6\u94a5\u7684\u60c5\u51b5\u4e0b\uff0c\u5b8c\u6210\u89e3\u5bc6\u3002\u8fd9\u80fd\u591f\u786e\u4fdd\u4fe1\u606f\u7684\u5b89\u5168\u6027\uff0c\u907f\u514d\u4e86\u76f4\u63a5\u4f20\u9012\u5bc6\u94a5\u6240\u9020\u6210\u7684\u88ab\u7834\u89e3\u7684\u98ce\u9669\u3002\u662f\u7531\u4e00\u5bf9\u5bc6\u94a5\u6765\u8fdb\u884c\u52a0\u89e3\u5bc6\u7684\u8fc7\u7a0b\uff0c\u5206\u522b\u79f0\u4e3a\u516c\u94a5\u548c\u79c1\u94a5\u3002\u4e24\u8005\u4e4b\u95f4\u6709\u6570\u5b66\u76f8\u5173\uff0c\u8be5\u52a0\u5bc6\u7b97\u6cd5\u7684\u539f\u7406\u5c31\u662f\u5bf9\u4e00\u6781\u5927\u6574\u6570\u505a\u56e0\u6570\u5206\u89e3\u7684\u56f0\u96be\u6027\u6765\u4fdd\u8bc1\u5b89\u5168\u6027\u3002\u901a\u5e38\u4e2a\u4eba\u4fdd\u5b58\u79c1\u94a5\uff0c\u516c\u94a5\u662f\u516c\u5f00\u7684\uff08\u53ef\u80fd\u540c\u65f6\u591a\u4eba\u6301\u6709\uff09\u3002<\/p>\n<p><!-- more --><\/p>\n<h2>RSA\u52a0\u5bc6\u3001\u7b7e\u540d\u533a\u522b<\/h2>\n<p>\u52a0\u5bc6\u548c\u7b7e\u540d\u90fd\u662f\u4e3a\u4e86\u5b89\u5168\u6027\u8003\u8651\uff0c\u4f46\u7565\u6709\u4e0d\u540c\u3002\u5e38\u6709\u4eba\u95ee\u52a0\u5bc6\u548c\u7b7e\u540d\u662f\u7528\u79c1\u94a5\u8fd8\u662f\u516c\u94a5\uff1f\u5176\u5b9e\u90fd\u662f\u5bf9\u52a0\u5bc6\u548c\u7b7e\u540d\u7684\u4f5c\u7528\u6709\u6240\u6df7\u6dc6\u3002\u7b80\u5355\u7684\u8bf4\uff0c\u52a0\u5bc6\u662f\u4e3a\u4e86\u9632\u6b62\u4fe1\u606f\u88ab\u6cc4\u9732\uff0c\u800c\u7b7e\u540d\u662f\u4e3a\u4e86\u9632\u6b62\u4fe1\u606f\u88ab\u7be1\u6539\u3002\u8fd9\u91cc\u4e3e2\u4e2a\u4f8b\u5b50\u8bf4\u660e\u3002<\/p>\n<h3>RSA\u52a0\u5bc6<\/h3>\n<p><strong>\u7b2c\u4e00\u4e2a\u573a\u666f<\/strong>\uff1aB\u8981\u7ed9A\u4f20\u9012\u4e00\u6761\u6d88\u606f\uff0c\u5185\u5bb9\u4e3a\u67d0\u4e00\u6570\u636e<\/p>\n<p>RSA\u7684\u52a0\u5bc6\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<p>\uff081\uff09A\u751f\u6210\u4e00\u5bf9\u5bc6\u94a5\uff08\u516c\u94a5\u548c\u79c1\u94a5\uff09\uff0c\u79c1\u94a5\u4e0d\u516c\u5f00\uff0cA\u81ea\u5df1\u4fdd\u7559\u3002\u516c\u94a5\u4e3a\u516c\u5f00\u7684\uff0c\u4efb\u4f55\u4eba\u53ef\u4ee5\u83b7\u53d6<\/p>\n<p>\uff082\uff09A\u4f20\u9012\u81ea\u5df1\u7684\u516c\u94a5\u7ed9B\uff0cB\u7528A\u7684\u516c\u94a5\u5bf9\u6d88\u606f\u8fdb\u884c\u52a0\u5bc6<\/p>\n<p>\uff083\uff09A\u63a5\u6536\u5230B\u52a0\u5bc6\u7684\u6d88\u606f\uff0c\u5229\u7528A\u81ea\u5df1\u7684\u79c1\u94a5\u5bf9\u6d88\u606f\u8fdb\u884c\u89e3\u5bc6<\/p>\n<p>\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u53ea\u67092\u6b21\u4f20\u9012\u8fc7\u7a0b\uff0c\u7b2c\u4e00\u6b21\u662fA\u4f20\u9012\u516c\u94a5\u7ed9B\uff0c\u7b2c\u4e8c\u6b21\u662fB\u4f20\u9012\u52a0\u5bc6\u6d88\u606f\u7ed9A\uff0c\u5373\u4f7f\u90fd\u88ab\u654c\u65b9\u622a\u83b7\uff0c\u4e5f\u6ca1\u6709\u5371\u9669\u6027\uff0c\u56e0\u4e3a\u53ea\u6709A\u7684\u79c1\u94a5\u624d\u80fd\u5bf9\u6d88\u606f\u8fdb\u884c\u89e3\u5bc6\uff0c\u9632\u6b62\u4e86\u6d88\u606f\u5185\u5bb9\u7684\u6cc4\u9732\u3002<\/p>\n<h3>RSA\u7b7e\u540d<\/h3>\n<p><strong>\u7b2c\u4e8c\u4e2a\u573a\u666f<\/strong>\uff1aA\u6536\u5230B\u53d1\u7684\u6d88\u606f\u540e\uff0c\u9700\u8981\u8fdb\u884c\u56de\u590d\u201c\u6536\u5230\u201d<\/p>\n<p>RSA\u7b7e\u540d\u7684\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<p>\uff081\uff09A\u751f\u6210\u4e00\u5bf9\u5bc6\u94a5\uff08\u516c\u94a5\u548c\u79c1\u94a5\uff09\uff0c\u79c1\u94a5\u4e0d\u516c\u5f00\uff0cA\u81ea\u5df1\u4fdd\u7559\u3002\u516c\u94a5\u4e3a\u516c\u5f00\u7684\uff0c\u4efb\u4f55\u4eba\u53ef\u4ee5\u83b7\u53d6<\/p>\n<p>\uff082\uff09A\u7528\u81ea\u5df1\u7684\u79c1\u94a5\u5bf9\u6d88\u606f\u52a0\u7b7e\uff0c\u5f62\u6210\u7b7e\u540d\uff0c\u5e76\u5c06\u52a0\u7b7e\u7684\u6d88\u606f\u548c\u6d88\u606f\u672c\u8eab\u4e00\u8d77\u4f20\u9012\u7ed9B<\/p>\n<p>\uff083\uff09B\u6536\u5230\u6d88\u606f\u540e\uff0c\u5728\u83b7\u53d6A\u7684\u516c\u94a5\u8fdb\u884c\u9a8c\u7b7e\uff0c\u5982\u679c\u9a8c\u7b7e\u51fa\u6765\u7684\u5185\u5bb9\u4e0e\u6d88\u606f\u672c\u8eab\u4e00\u81f4\uff0c\u8bc1\u660e\u6d88\u606f\u662fA\u56de\u590d\u7684<\/p>\n<p>\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u53ea\u67092\u6b21\u4f20\u9012\u8fc7\u7a0b\uff0c\u7b2c\u4e00\u6b21\u662fA\u4f20\u9012\u52a0\u7b7e\u7684\u6d88\u606f\u548c\u6d88\u606f\u672c\u8eab\u7ed9B\uff0c\u7b2c\u4e8c\u6b21\u662fB\u83b7\u53d6A\u7684\u516c\u94a5\uff0c\u5373\u4f7f\u90fd\u88ab\u654c\u65b9\u622a\u83b7\uff0c\u4e5f\u6ca1\u6709\u5371\u9669\u6027\uff0c\u56e0\u4e3a\u53ea\u6709A\u7684\u79c1\u94a5\u624d\u80fd\u5bf9\u6d88\u606f\u8fdb\u884c\u7b7e\u540d\uff0c\u5373\u4f7f\u77e5\u9053\u4e86\u6d88\u606f\u5185\u5bb9\uff0c\u4e5f\u65e0\u6cd5\u4f2a\u9020\u5e26\u7b7e\u540d\u7684\u56de\u590d\u7ed9B\uff0c\u9632\u6b62\u4e86\u6d88\u606f\u5185\u5bb9\u7684\u7be1\u6539\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u7efc\u5408\u4e24\u4e2a\u573a\u666f\u4f60\u4f1a\u53d1\u73b0\uff0c\u7b2c\u4e00\u4e2a\u573a\u666f\u867d\u7136\u88ab\u622a\u83b7\u7684\u6d88\u606f\u6ca1\u6709\u6cc4\u9732\uff0c\u4f46\u662f\u53ef\u4ee5\u5229\u7528\u622a\u83b7\u7684\u516c\u94a5\uff0c\u5c06\u5047\u6570\u636e\u8fdb\u884c\u52a0\u5bc6\uff0c\u7136\u540e\u4f20\u9012\u7ed9A\u3002\u7b2c\u4e8c\u4e2a\u573a\u666f\u867d\u7136\u622a\u83b7\u7684\u6d88\u606f\u4e0d\u80fd\u88ab\u7be1\u6539\uff0c\u4f46\u662f\u6d88\u606f\u7684\u5185\u5bb9\u53ef\u4ee5\u76f4\u63a5\u83b7\u5f97\uff0c\u5e76\u4e0d\u80fd\u9632\u6b62\u6cc4\u9732\u3002\u6240\u4ee5\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u8981\u6839\u636e\u60c5\u51b5\u4f7f\u7528\uff0c\u4e5f\u53ef\u4ee5\u540c\u65f6\u4f7f\u7528\u52a0\u5bc6\u548c\u7b7e\u540d\uff0c\u6bd4\u5982A\u548cB\u90fd\u6709\u4e00\u5957\u81ea\u5df1\u7684\u516c\u94a5\u548c\u79c1\u94a5\uff0c\u5f53A\u8981\u7ed9B\u53d1\u9001\u6d88\u606f\u65f6\uff0c\u5148\u7528B\u7684\u516c\u94a5\u5bf9\u6d88\u606f\u52a0\u5bc6\uff0c\u518d\u5bf9\u52a0\u5bc6\u7684\u6d88\u606f\u4f7f\u7528A\u7684\u79c1\u94a5\u52a0\u7b7e\u540d\uff0c\u8fbe\u5230\u65e2\u4e0d\u6cc4\u9732\u4e5f\u4e0d\u88ab\u7be1\u6539\uff0c\u66f4\u80fd\u4fdd\u8bc1\u6d88\u606f\u7684\u5b89\u5168\u6027\u3002<\/p>\n<blockquote>\n<p>\u603b\u7ed3\uff1a\u516c\u94a5\u52a0\u5bc6\u3001\u79c1\u94a5\u89e3\u5bc6\u3001\u79c1\u94a5\u7b7e\u540d\u3001\u516c\u94a5\u9a8c\u7b7e\u3002<\/p>\n<\/blockquote>\n<h2>RSA\u52a0\u5bc6\u3001\u7b7e\u540d\u7684\u65b9\u6cd5<\/h2>\n<p>\u4ee3\u7801\u4f8b\u5b50\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-java\">import org.apache.commons.codec.binary.Base64;\n\nimport javax.crypto.Cipher;\nimport java.io.ByteArrayOutputStream;\nimport java.security.*;\nimport java.security.spec.PKCS8EncodedKeySpec;\nimport java.security.spec.X509EncodedKeySpec;\n\npublic class TestRSA {\n\n    \/**\n     * RSA\u6700\u5927\u52a0\u5bc6\u660e\u6587\u5927\u5c0f\n     *\/\n    private static final int MAX_ENCRYPT_BLOCK = 117;\n\n    \/**\n     * RSA\u6700\u5927\u89e3\u5bc6\u5bc6\u6587\u5927\u5c0f\n     *\/\n    private static final int MAX_DECRYPT_BLOCK = 128;\n\n    \/**\n     * \u83b7\u53d6\u5bc6\u94a5\u5bf9\n     *\n     * @return \u5bc6\u94a5\u5bf9\n     *\/\n    public static KeyPair getKeyPair() throws Exception {\n        KeyPairGenerator generator = KeyPairGenerator.getInstance(&quot;RSA&quot;);\n        generator.initialize(1024);\n        return generator.generateKeyPair();\n    }\n\n    \/**\n     * \u83b7\u53d6\u79c1\u94a5\n     *\n     * @param privateKey \u79c1\u94a5\u5b57\u7b26\u4e32\n     * @return\n     *\/\n    public static PrivateKey getPrivateKey(String privateKey) throws Exception {\n        KeyFactory keyFactory = KeyFactory.getInstance(&quot;RSA&quot;);\n        byte[] decodedKey = Base64.decodeBase64(privateKey.getBytes());\n        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decodedKey);\n        return keyFactory.generatePrivate(keySpec);\n    }\n\n    \/**\n     * \u83b7\u53d6\u516c\u94a5\n     *\n     * @param publicKey \u516c\u94a5\u5b57\u7b26\u4e32\n     * @return\n     *\/\n    public static PublicKey getPublicKey(String publicKey) throws Exception {\n        KeyFactory keyFactory = KeyFactory.getInstance(&quot;RSA&quot;);\n        byte[] decodedKey = Base64.decodeBase64(publicKey.getBytes());\n        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(decodedKey);\n        return keyFactory.generatePublic(keySpec);\n    }\n\n    \/**\n     * RSA\u52a0\u5bc6\n     *\n     * @param data \u5f85\u52a0\u5bc6\u6570\u636e\n     * @param publicKey \u516c\u94a5\n     * @return\n     *\/\n    public static String encrypt(String data, PublicKey publicKey) throws Exception {\n        Cipher cipher = Cipher.getInstance(&quot;RSA&quot;);\n        cipher.init(Cipher.ENCRYPT_MODE, publicKey);\n        int inputLen = data.getBytes().length;\n        ByteArrayOutputStream out = new ByteArrayOutputStream();\n        int offset = 0;\n        byte[] cache;\n        int i = 0;\n        \/\/ \u5bf9\u6570\u636e\u5206\u6bb5\u52a0\u5bc6\n        while (inputLen - offset &gt; 0) {\n            if (inputLen - offset &gt; MAX_ENCRYPT_BLOCK) {\n                cache = cipher.doFinal(data.getBytes(), offset, MAX_ENCRYPT_BLOCK);\n            } else {\n                cache = cipher.doFinal(data.getBytes(), offset, inputLen - offset);\n            }\n            out.write(cache, 0, cache.length);\n            i++;\n            offset = i * MAX_ENCRYPT_BLOCK;\n        }\n        byte[] encryptedData = out.toByteArray();\n        out.close();\n        \/\/ \u83b7\u53d6\u52a0\u5bc6\u5185\u5bb9\u4f7f\u7528base64\u8fdb\u884c\u7f16\u7801,\u5e76\u4ee5UTF-8\u4e3a\u6807\u51c6\u8f6c\u5316\u6210\u5b57\u7b26\u4e32\n        \/\/ \u52a0\u5bc6\u540e\u7684\u5b57\u7b26\u4e32\n        return new String(Base64.encodeBase64String(encryptedData));\n    }\n\n    \/**\n     * RSA\u89e3\u5bc6\n     *\n     * @param data \u5f85\u89e3\u5bc6\u6570\u636e\n     * @param privateKey \u79c1\u94a5\n     * @return\n     *\/\n    public static String decrypt(String data, PrivateKey privateKey) throws Exception {\n        Cipher cipher = Cipher.getInstance(&quot;RSA&quot;);\n        cipher.init(Cipher.DECRYPT_MODE, privateKey);\n        byte[] dataBytes = Base64.decodeBase64(data);\n        int inputLen = dataBytes.length;\n        ByteArrayOutputStream out = new ByteArrayOutputStream();\n        int offset = 0;\n        byte[] cache;\n        int i = 0;\n        \/\/ \u5bf9\u6570\u636e\u5206\u6bb5\u89e3\u5bc6\n        while (inputLen - offset &gt; 0) {\n            if (inputLen - offset &gt; MAX_DECRYPT_BLOCK) {\n                cache = cipher.doFinal(dataBytes, offset, MAX_DECRYPT_BLOCK);\n            } else {\n                cache = cipher.doFinal(dataBytes, offset, inputLen - offset);\n            }\n            out.write(cache, 0, cache.length);\n            i++;\n            offset = i * MAX_DECRYPT_BLOCK;\n        }\n        byte[] decryptedData = out.toByteArray();\n        out.close();\n        \/\/ \u89e3\u5bc6\u540e\u7684\u5185\u5bb9\n        return new String(decryptedData, &quot;UTF-8&quot;);\n    }\n\n    \/**\n     * \u7b7e\u540d\n     *\n     * @param data \u5f85\u7b7e\u540d\u6570\u636e\n     * @param privateKey \u79c1\u94a5\n     * @return \u7b7e\u540d\n     *\/\n    public static String sign(String data, PrivateKey privateKey) throws Exception {\n        byte[] keyBytes = privateKey.getEncoded();\n        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);\n        KeyFactory keyFactory = KeyFactory.getInstance(&quot;RSA&quot;);\n        PrivateKey key = keyFactory.generatePrivate(keySpec);\n        Signature signature = Signature.getInstance(&quot;MD5withRSA&quot;);\n        signature.initSign(key);\n        signature.update(data.getBytes());\n        return new String(Base64.encodeBase64(signature.sign()));\n    }\n\n    \/**\n     * \u9a8c\u7b7e\n     *\n     * @param srcData \u539f\u59cb\u5b57\u7b26\u4e32\n     * @param publicKey \u516c\u94a5\n     * @param sign \u7b7e\u540d\n     * @return \u662f\u5426\u9a8c\u7b7e\u901a\u8fc7\n     *\/\n    public static boolean verify(String srcData, PublicKey publicKey, String sign) throws Exception {\n        byte[] keyBytes = publicKey.getEncoded();\n        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);\n        KeyFactory keyFactory = KeyFactory.getInstance(&quot;RSA&quot;);\n        PublicKey key = keyFactory.generatePublic(keySpec);\n        Signature signature = Signature.getInstance(&quot;MD5withRSA&quot;);\n        signature.initVerify(key);\n        signature.update(srcData.getBytes());\n        return signature.verify(Base64.decodeBase64(sign.getBytes()));\n    }\n\n    public static void main(String[] args) {\n        try {\n            \/\/ \u751f\u6210\u5bc6\u94a5\u5bf9\n            KeyPair keyPair = getKeyPair();\n            String privateKey = new String(Base64.encodeBase64(keyPair.getPrivate().getEncoded()));\n            String publicKey = new String(Base64.encodeBase64(keyPair.getPublic().getEncoded()));\n            System.out.println(&quot;\u79c1\u94a5: &quot; + privateKey);\n            System.out.println(&quot;\u516c\u94a5: &quot; + publicKey);\n            String data = &quot;http:\/\/www.appblog.cn&quot;;\n\n            \/\/ RSA\u52a0\u5bc6\n            String encryptData = encrypt(data, getPublicKey(publicKey));\n            System.out.println(&quot;\u52a0\u5bc6\u540e\u5185\u5bb9: &quot; + encryptData);\n            \/\/ RSA\u89e3\u5bc6\n            String decryptData = decrypt(encryptData, getPrivateKey(privateKey));\n            System.out.println(&quot;\u89e3\u5bc6\u540e\u5185\u5bb9: &quot; + decryptData);\n\n            \/\/ RSA\u7b7e\u540d\n            String sign = sign(data, getPrivateKey(privateKey));\n            System.out.println(&quot;\u7b7e\u540d: &quot; + sign);\n            \/\/ RSA\u9a8c\u7b7e\n            boolean result = verify(data, getPublicKey(publicKey), sign);\n            System.out.println(&quot;\u9a8c\u7b7e\u7ed3\u679c: &quot; + result);\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n\n}<\/code><\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c<\/p>\n<pre><code>\u79c1\u94a5: MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJnKdsKYoiqbpw1iUsZtVCvybeU2iKkc9zaq40CxiGYZrHnApAn8bHUNNdv0nmbdOIhwVuYrVVYkOsryHAW0UnY4C2w4rWE0dj8DVKoXvH\/iJN3h86UNAkEVi\/ajri2m0yCewEAlr2a6a0Y609dev2PSytd+ZS5s9moaSR1k\/w9FAgMBAAECgYEAhW3fs93xdL4vJbGU14urZ6WiKygxUWhMJCYHnO1qxgqoVcoJiJB1GOkpPXjypZRxpA6zlmcqVt6AE+wS2\/AjSg3aFfSVWw89Ee5pRSjbTMXif0cbL47zKEceGmmwe7CCP6J8T4Tn0QrVYkKHiCPhnRRahhTQboeQlLu\/HbhKvIECQQDK6GmLRfTc\/LOIg8ziLo4klVvVrH5xp0utneK2Rx0O4L1vykuhQ\/B+nn4zl\/VZbyHaHYwWOyWNELu3Qzg8tBhJAkEAwgf\/Yz7VC1BDOrmUiGBfsvA\/df+f3u5wYVPy3Q4lv\/RU71Wux8bnTRPpnZ7G8AlsZF+XlqumQaw\/qkSUEJvXHQJAS\/TGlblBWXxLZL4Z802ELlOvBgTFbJw4qyxgUuW6Dfi5UWDEAQFixLNmAMBQuwLsBC9tYmEPxIfQDWFfavHr6QJAIPUy0CzQC0fq44K6VB\/qoX5liSmOglOGC0IzMpFAoEZkVvL66TxD9be4KunZaNRw8Ou71\/\/4EZesiMN1UwzlkQJBAJv7qzvtY+yX46+3IN2Ao4FXjwbpDH3IH2BvmLm1q81gY5W3AQ7gp\/umDY7C4M9rXSIN888V5K4h6egrHeCs0CQ=\n\u516c\u94a5: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZynbCmKIqm6cNYlLGbVQr8m3lNoipHPc2quNAsYhmGax5wKQJ\/Gx1DTXb9J5m3TiIcFbmK1VWJDrK8hwFtFJ2OAtsOK1hNHY\/A1SqF7x\/4iTd4fOlDQJBFYv2o64tptMgnsBAJa9mumtGOtPXXr9j0srXfmUubPZqGkkdZP8PRQIDAQAB\n\u52a0\u5bc6\u540e\u5185\u5bb9: kyU9vXSV+BJn3OgvXIWRDJGWoynPjOF1+1Ea+HplAu7OycUG4RvhAd7KI1RPoF4GUKh7F4aoPmQ+9nDnnkpd\/vTt5gOzZhcnvsqsIOg+Vh+\/DT\/z\/gmCX+C5nbXxDP3puawcalxmuork4dqAGT38JtoWcBEgi0q5M3Vkwf0IspY=\n\u89e3\u5bc6\u540e\u5185\u5bb9: http:\/\/www.appblog.cn\n\u7b7e\u540d: dvyoOmuMZSmQEnM9Z+Quz8pyloJDvZTv1p\/CcB3z+5bQGVfCVFjUCJsDImRvTivqeiThM0dZV6m78FcOP27o8BkNsndkNMRxLCn8e\/hOFIWnpCK\/Uhsp9crxAp6IJisTjwBiDd8sWbH4VzUZAZ1vgUXUUzX3GolHcPKp8lmZp3Q=\n\u9a8c\u7b7e\u7ed3\u679c: true<\/code><\/pre>\n<blockquote>\n<p>RSA\u52a0\u5bc6\u5bf9\u660e\u6587\u7684\u957f\u5ea6\u6709\u6240\u9650\u5236\uff0c\u89c4\u5b9a\u9700\u52a0\u5bc6\u7684\u660e\u6587\u6700\u5927\u957f\u5ea6=\u5bc6\u94a5\u957f\u5ea6-11\uff08\u5355\u4f4d\u662f\u5b57\u8282\uff0c\u5373byte\uff09\uff0c\u6240\u4ee5\u5728\u52a0\u5bc6\u548c\u89e3\u5bc6\u7684\u8fc7\u7a0b\u4e2d\u9700\u8981\u5206\u5757\u8fdb\u884c\u3002\u800c\u5bc6\u94a5\u9ed8\u8ba4\u662f1024\u4f4d\uff0c\u53731024\u4f4d\/8\u4f4d-11=128-11=117\u5b57\u8282\u3002\u6240\u4ee5\u9ed8\u8ba4\u52a0\u5bc6\u524d\u7684\u660e\u6587\u6700\u5927\u957f\u5ea6117\u5b57\u8282\uff0c\u89e3\u5bc6\u5bc6\u6587\u6700\u5927\u957f\u5ea6\u4e3a128\u5b57\u8282\u3002\u90a3\u4e48\u4e3a\u5565\u4e24\u8005\u76f8\u5dee11\u5b57\u8282\u5462\uff1f\u662f\u56e0\u4e3aRSA\u52a0\u5bc6\u4f7f\u7528\u5230\u4e86\u586b\u5145\u6a21\u5f0f\uff08padding\uff09\uff0c\u5373\u5185\u5bb9\u4e0d\u8db3117\u5b57\u8282\u65f6\u4f1a\u81ea\u52a8\u586b\u6ee1\uff0c\u7528\u5230\u586b\u5145\u6a21\u5f0f\u81ea\u7136\u4f1a\u5360\u7528\u4e00\u5b9a\u7684\u5b57\u8282\uff0c\u800c\u4e14\u8fd9\u90e8\u5206\u5b57\u8282\u4e5f\u662f\u53c2\u4e0e\u52a0\u5bc6\u7684\u3002<\/p>\n<\/blockquote>\n<p>\u5bc6\u94a5\u957f\u5ea6\u7684\u8bbe\u7f6e\u5c31\u662f<code>generator.initialize(1024)<\/code>\u8fd9\u4e00\u884c\u3002\u53ef\u81ea\u884c\u8c03\u6574\uff0c\u5f53\u7136\u975e\u5bf9\u79f0\u52a0\u5bc6\u968f\u7740\u5bc6\u94a5\u53d8\u957f\uff0c\u5b89\u5168\u6027\u4e0a\u5347\u7684\u540c\u65f6\u6027\u80fd\u4e5f\u4f1a\u6709\u6240\u4e0b\u964d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>RSA\u52a0\u5bc6\u7b80\u4ecb RSA\u52a0\u5bc6\u662f\u4e00\u79cd\u975e\u5bf9\u79f0\u52a0\u5bc6\u3002\u53ef\u4ee5\u5728\u4e0d\u76f4\u63a5\u4f20\u9012\u5bc6\u94a5\u7684\u60c5\u51b5\u4e0b\uff0c\u5b8c\u6210\u89e3\u5bc6\u3002\u8fd9\u80fd\u591f\u786e\u4fdd\u4fe1\u606f\u7684\u5b89\u5168\u6027\uff0c\u907f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[108],"class_list":["post-331","post","type-post","status-publish","format-standard","hentry","category-java-basic","tag-rsa"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=331"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/331\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}