{"id":216,"date":"2021-08-28T12:14:13","date_gmt":"2021-08-28T04:14:13","guid":{"rendered":"https:\/\/fugary.com\/?p=216"},"modified":"2021-08-28T12:14:13","modified_gmt":"2021-08-28T04:14:13","slug":"springboot%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e5%8a%a0%e5%af%86","status":"publish","type":"post","link":"https:\/\/fugary.com\/?p=216","title":{"rendered":"SpringBoot\u914d\u7f6e\u6587\u4ef6\u52a0\u5bc6"},"content":{"rendered":"<h2>SpringBoot\u914d\u7f6e\u6587\u4ef6\u52a0\u5bc6<\/h2>\n<p>\u516c\u53f8\u4e3a\u4e86\u589e\u52a0\u914d\u7f6e\u6587\u4ef6\u5b89\u5168\u6027\uff0c\u914d\u7f6e\u6587\u4ef6\u4e2d\u4e0d\u80fd\u7528\u660e\u6587\u7684\u6570\u636e\u5e93\u8fde\u63a5\u5bc6\u7801\u7b49\u4fe1\u606f\uff0c\u56e0\u6b64\u9700\u8981\u5bf9application.yml\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u5bc6\u7801\u52a0\u5bc6\uff0c\u641c\u4e86\u4e0b\u53d1\u73b0<code>springboot<\/code>\u4e2d\u6bd4\u8f83\u5e38\u7528\u7684\u52a0\u5bc6\u6846\u67b6\u662f<code>jasypt<\/code><\/p>\n<h3>\u4e0b\u8f7djasypt<\/h3>\n<p>\u4e0b\u8f7d\u5730\u5740\uff1a <\/p>\n<p><a href=\"https:\/\/github.com\/jasypt\/jasypt\/releases\/tag\/jasypt-1.9.3\">https:\/\/github.com\/jasypt\/jasypt\/releases\/tag\/jasypt-1.9.3<\/a><\/p>\n<p>\u91cc\u9762\u63d0\u4f9b\u4e00\u4e9b\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u4f7f\u7528\uff0c\u4ee3\u7801\u4e2d\u4f7f\u7528\u53ef\u4ee5\u7528maven\u5f15\u5165\u3002<\/p>\n<h3>\u5f15\u5165jasypt<\/h3>\n<p>\u4f7f\u7528<code>Maven<\/code>\u5f15\u5165\uff0c\u73b0\u5728\u662f3.0.3\u7248\u672c\uff1a<\/p>\n<pre><code class=\"language-xml\">&lt;dependency&gt;\n    &lt;groupId&gt;com.github.ulisesbocchio&lt;\/groupId&gt;\n    &lt;artifactId&gt;jasypt-spring-boot-starter&lt;\/artifactId&gt;\n    &lt;version&gt;${jasypt-spring.version}&lt;\/version&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n<h3>\u914d\u7f6ejasypt<\/h3>\n<p>\u914d\u7f6e\u52a0\u5bc6\u5bc6\u7801\uff1a<\/p>\n<pre><code class=\"language-yml\">jasypt:\n  encryptor:\n    password: 12345678<\/code><\/pre>\n<p>\u53ef\u4ee5\u5148\u4f7f\u7528<code>jasypt<\/code>\u6765\u751f\u6210\u52a0\u5bc6\u5b57\u7b26\u4e32<\/p>\n<pre><code class=\"language-java\">    @Autowired\n    private StringEncryptor jasyptStringEncryptor;\n\n    @PostMapping(&quot;\/encrypt&quot;)\n    public BaseStrResult encrypt(@RequestBody BaseStrParam param){\n        String encryptStr = jasyptStringEncryptor.encrypt(param.getInput());\n        BaseStrResult result = new BaseStrResult();\n        result.setResult(encryptStr);\n        return result.success();\n    }<\/code><\/pre>\n<p>\u914d\u7f6e\u5230\u914d\u7f6e\u6587\u4ef6\u4e2d<\/p>\n<pre><code class=\"language-yml\">spring:\n  datasource:\n    password: ENC(LGw2sBBoQ061HhpCPS7lgiOWCfHxUonaDy2GtY6W+\/tJakz1jKHhBSHQ6j3K0LFt)<\/code><\/pre>\n<p>\u53ef\u4ee5\u6b63\u5e38\u542f\u52a8\u5c31\u8868\u793a\u6210\u529f\u4e86\u3002<\/p>\n<h3>jasypt\u914d\u7f6e\u7b97\u6cd5<\/h3>\n<p>\u9ed8\u8ba4jasypt\u4f7f\u7528\u7684\u7b97\u6cd5\u662f\uff1aPBEWITHHMACSHA512ANDAES_256\uff0c\u57fa\u4e8e\u5bc6\u7801\u7684SHA512+AES\u7b97\u6cd5\uff0c\u9700\u8981 Java JDK 1.9+<\/p>\n<p>\u67e5\u770b\u652f\u6301\u7684\u7b97\u6cd5\uff1a<\/p>\n<pre><code class=\"language-bat\">$ listAlgorithms.bat\n\nDIGEST ALGORITHMS:   [MD2, MD5, SHA, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512\/224, SHA-512\/256, SHA3-224, SHA3-256, SHA3-384, SHA3-5\n12]\n\nPBE ALGORITHMS:      [PBEWITHHMACSHA1ANDAES_128, PBEWITHHMACSHA1ANDAES_256, PBEWITHHMACSHA224ANDAES_128, PBEWITHHMACSHA224ANDAES_256, P\nBEWITHHMACSHA256ANDAES_128, PBEWITHHMACSHA256ANDAES_256, PBEWITHHMACSHA384ANDAES_128, PBEWITHHMACSHA384ANDAES_256, PBEWITHHMACSHA512AND\nAES_128, PBEWITHHMACSHA512ANDAES_256, PBEWITHMD5ANDDES, PBEWITHMD5ANDTRIPLEDES, PBEWITHSHA1ANDDESEDE, PBEWITHSHA1ANDRC2_128, PBEWITHSHA\n1ANDRC2_40, PBEWITHSHA1ANDRC4_128, PBEWITHSHA1ANDRC4_40]<\/code><\/pre>\n<p>\u53ef\u4ee5\u9009\u62e9\u9700\u8981\u4f7f\u7528\u7684\u7b97\u6cd5\u52a0\u5bc6\u3002<\/p>\n<h3>jasypt\u547d\u4ee4\u884c\u5de5\u5177<\/h3>\n<p>\u4eceGithub\u4e0b\u8f7d\u7684\u6587\u4ef6jasypt-1.9.3-dist.zip\u89e3\u538b\u540e\u53ef\u4ee5\u770b\u5230bin\u76ee\u5f55\u4e0b\u6709\u4e0d\u5c11\u5de5\u5177<\/p>\n<p>listAlgorithms.bat\u83b7\u53d6\u652f\u6301\u7684\u7b97\u6cd5<\/p>\n<p>\u547d\u4ee4\u884c\u52a0\u5bc6\u5de5\u5177\u5e2e\u52a9\uff1a<\/p>\n<pre><code class=\"language-shell\">.\\encrypt.bat\nUSAGE: encrypt.bat [ARGUMENTS]\n  * \u53c2\u6570\u683c\u5f0f:\n      &quot;arg1=value1 arg2=value2 arg3=value3 ...&quot;\n  * \u5fc5\u586b\u53c2\u6570:\n      input\n      password\n  * \u53ef\u9009\u53c2\u6570:\n      verbose\n      algorithm\n      keyObtentionIterations\n      saltGeneratorClassName\n      providerName\n      providerClassName\n      stringOutputType\n      ivGeneratorClassName<\/code><\/pre>\n<p>\u547d\u4ee4\u884c\u52a0\u5bc6\uff1a<\/p>\n<pre><code class=\"language-shell\"># \u52a0\u5bc6\nencrypt.bat input=&quot;12345678&quot; password=&quot;1234567890&quot; algorithm=PBEWITHHMACSHA512ANDAES_256 ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator\n# \u89e3\u5bc6\ndecrypt.bat input=&quot;B8HS1fG8WQwxtIw+SnExxLrUal8hJ516H3DiwdbJIztvxWIMT2TL1y7uqPdX\/P+9&quot; password=&quot;1234567890&quot; algorithm=PBEWITHHMACSHA512ANDAES_256 ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SpringBoot\u914d\u7f6e\u6587\u4ef6\u52a0\u5bc6 \u516c\u53f8\u4e3a\u4e86\u589e\u52a0\u914d\u7f6e\u6587\u4ef6\u5b89\u5168\u6027\uff0c\u914d\u7f6e\u6587\u4ef6\u4e2d\u4e0d\u80fd\u7528\u660e\u6587\u7684\u6570\u636e\u5e93\u8fde\u63a5\u5bc6\u7801\u7b49\u4fe1\u606f\uff0c\u56e0\u6b64 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,2],"tags":[47,48],"_links":{"self":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/216"}],"collection":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=216"}],"version-history":[{"count":1,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/216\/revisions"}],"predecessor-version":[{"id":217,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/216\/revisions\/217"}],"wp:attachment":[{"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}