{"id":6017,"date":"2024-08-01T22:48:52","date_gmt":"2024-08-01T14:48:52","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=6017"},"modified":"2024-08-01T22:48:52","modified_gmt":"2024-08-01T14:48:52","slug":"spring-boot-%e4%bd%bf%e7%94%a8-aes-%e5%8a%a0%e5%af%86%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring-boot\/spring-boot-%e4%bd%bf%e7%94%a8-aes-%e5%8a%a0%e5%af%86%e8%af%a6%e8%a7%a3\/","title":{"rendered":"Spring Boot \u4f7f\u7528 AES \u52a0\u5bc6\u8be6\u89e3"},"content":{"rendered":"<div class='wxsyncmain'>\n<section data-tool=\"markdown2wechat\u7f16\u8f91\u5668\" data-website=\"https:\/\/aizhuanqian.com\" style=\"font-size: 16px;padding-right: 10px;padding-left: 10px;word-break: break-word;text-align: left;line-height: 1.75;color: rgb(89, 89, 89);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%);background-size: 20px 20px;background-position: center center;\">\n<blockquote data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-size: 0.9em;overflow: auto;padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;text-size-adjust: 100%;line-height: 1.55em;border-radius: 6px;color: rgb(89, 89, 89);box-sizing: inherit;border-width: 1px;border-top-style: solid;border-right-style: solid;border-bottom-style: solid;border-color: rgb(222, 198, 251);background: rgb(246, 238, 255);\"><p><span style=\"color: #DEC6FB;font-size: 34px;line-height: 1;font-weight: 700;\">\u275d<\/span><\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;font-size: 14px;word-spacing: 2px;line-height: 26px;\">AES\uff08Advanced Encryption Standard\uff0c\u9ad8\u7ea7\u52a0\u5bc6\u6807\u51c6\uff09\u662f\u4e00\u79cd\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u6570\u636e\u52a0\u5bc6\u9886\u57df\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728 Spring Boot \u9879\u76ee\u4e2d\u4f7f\u7528 AES \u8fdb\u884c\u6570\u636e\u52a0\u5bc6\u548c\u89e3\u5bc6\u3002<\/p>\n<p><span style=\"float: right;color: #DEC6FB;\">\u275e<\/span><\/p><\/blockquote>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;color: black;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"display: none;\"><\/span><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left: 5px solid rgb(222, 198, 251);color: rgb(89, 89, 89);\">\u57fa\u672c\u6982\u5ff5<\/span><span><\/span><\/h2>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;color: black;font-weight: bold;text-align: center;\"><span style=\"display: none;\"><\/span><span style=\"border-bottom: 2px solid #DEC6FB;color: #595959;\">\u5bf9\u79f0\u52a0\u5bc6<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5bf9\u79f0\u52a0\u5bc6\u4f7f\u7528\u76f8\u540c\u7684\u5bc6\u94a5\u8fdb\u884c\u52a0\u5bc6\u548c\u89e3\u5bc6\u3002\u52a0\u5bc6\u548c\u89e3\u5bc6\u8fc7\u7a0b\u4e2d\u7684\u5bc6\u94a5\u5fc5\u987b\u4fdd\u5bc6\uff0c\u53ea\u6709\u52a0\u5bc6\u65b9\u548c\u89e3\u5bc6\u65b9\u77e5\u9053\u8be5\u5bc6\u94a5\u3002<\/p>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;color: black;font-weight: bold;text-align: center;\"><span style=\"display: none;\"><\/span><span style=\"border-bottom: 2px solid #DEC6FB;color: #595959;\">AES \u5bc6\u94a5\u957f\u5ea6<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">AES \u652f\u6301\u4e09\u79cd\u5bc6\u94a5\u957f\u5ea6\uff1a<\/p>\n<ul data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-1\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;\">128 \u4f4d<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;\">192 \u4f4d<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;\">256 \u4f4d<\/section>\n<\/li>\n<\/ul>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e0d\u540c\u7684\u5bc6\u94a5\u957f\u5ea6\u5bf9\u5e94\u4e0d\u540c\u7684\u5b89\u5168\u5f3a\u5ea6\u548c\u8ba1\u7b97\u5f00\u9500\u3002<\/p>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;color: black;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"display: none;\"><\/span><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left: 5px solid rgb(222, 198, 251);color: rgb(89, 89, 89);\">\u5728 Spring Boot \u9879\u76ee\u4e2d\u5b9e\u6218\u6f14\u7ec3<\/span><span><\/span><\/h2>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;color: black;font-weight: bold;text-align: center;\"><span style=\"display: none;\"><\/span><span style=\"border-bottom: 2px solid #DEC6FB;color: #595959;\">\u914d\u7f6e\u52a0\u5bc6\u5bc6\u94a5<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5728 application.yml \u6587\u4ef6\u4e2d\u914d\u7f6e\u52a0\u5bc6\u5bc6\u94a5\uff1a<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background: url(&quot;https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223413473.jpeg&quot;) 10px 10px \/ 40px no-repeat rgb(40, 44, 52);height: 30px;width: 100%;margin-bottom: -7px;border-radius: 5px;\"><\/span><code style=\"overflow-x: auto;padding: 16px;color: #abb2bf;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;font-size: 12px;-webkit-overflow-scrolling: touch;padding-top: 15px;background: #282c34;border-radius: 5px;\"><span style=\"color: #c678dd;line-height: 26px;\">import<\/span>com.example.securityapi.utils.AESUtil;<span style=\"color: #c678dd;line-height: 26px;\">import<\/span>org.springframework.web.bind.annotation.GetMapping;<span style=\"color: #c678dd;line-height: 26px;\">import<\/span>org.springframework.web.bind.annotation.RequestParam;<span style=\"color: #c678dd;line-height: 26px;\">import<\/span>org.springframework.web.bind.annotation.RestController;<span style=\"color: #61aeee;line-height: 26px;\">@RestController<\/span><span style=\"color: #c678dd;line-height: 26px;\">public<\/span><span style=\"line-height: 26px;\"><span style=\"color: #c678dd;line-height: 26px;\">class<\/span><span style=\"color: #e6c07b;line-height: 26px;\">EncryptionController<\/span><\/span>{<span style=\"color: #61aeee;line-height: 26px;\">@GetMapping<\/span>(<span style=\"color: #98c379;line-height: 26px;\">\"\/encrypt\"<\/span>)<span style=\"line-height: 26px;\"><span style=\"color: #c678dd;line-height: 26px;\">public<\/span>String<span style=\"color: #61aeee;line-height: 26px;\">encrypt<\/span><span style=\"line-height: 26px;\">(@RequestParamStringdata)<\/span><\/span>{<span style=\"color: #c678dd;line-height: 26px;\">try<\/span>{<span style=\"color: #c678dd;line-height: 26px;\">return<\/span>AESUtil.encrypt(data);}<span style=\"color: #c678dd;line-height: 26px;\">catch<\/span>(Exceptione){<span style=\"color: #c678dd;line-height: 26px;\">return<\/span><span style=\"color: #98c379;line-height: 26px;\">\"\u52a0\u5bc6\u5931\u8d25:\"<\/span>+e.getMessage();}}<span style=\"color: #61aeee;line-height: 26px;\">@GetMapping<\/span>(<span style=\"color: #98c379;line-height: 26px;\">\"\/decrypt\"<\/span>)<span style=\"line-height: 26px;\"><span style=\"color: #c678dd;line-height: 26px;\">public<\/span>String<span style=\"color: #61aeee;line-height: 26px;\">decrypt<\/span><span style=\"line-height: 26px;\">(@RequestParamStringdata)<\/span><\/span>{<span style=\"color: #c678dd;line-height: 26px;\">try<\/span>{<span style=\"color: #c678dd;line-height: 26px;\">return<\/span>AESUtil.decrypt(data);}<span style=\"color: #c678dd;line-height: 26px;\">catch<\/span>(Exceptione){<span style=\"color: #c678dd;line-height: 26px;\">return<\/span><span style=\"color: #98c379;line-height: 26px;\">\"\u89e3\u5bc6\u5931\u8d25:\"<\/span>+e.getMessage();}}}<\/code><\/pre>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;color: black;font-weight: bold;text-align: center;\"><span style=\"display: none;\"><\/span><span style=\"border-bottom: 2px solid #DEC6FB;color: #595959;\">\u8fd0\u884c\u4f60\u7684\u9879\u76ee<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u8fd0\u884c\u4f60\u7684 Spring Boot \u5e94\u7528\uff0c\u5e76\u901a\u8fc7\u6d4f\u89c8\u5668\u6216 Postman \u6765\u6d4b\u8bd5 API \u52a0\u5bc6\u548c\u89e3\u5bc6\u529f\u80fd\u3002\u8bbf\u95ee\u4ee5\u4e0bURL\u6765\u6d4b\u8bd5\uff1a<\/p>\n<ul data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-1\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;\">\u52a0\u5bc6\u6570\u636e\uff1ahttp:\/\/localhost:8080\/encrypt?data=hello<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;\">\u89e3\u5bc6\u6570\u636e\uff1ahttp:\/\/localhost:8080\/decrypt?data=\u52a0\u5bc6\u540e\u7684\u6570\u636e<\/section>\n<\/li>\n<\/ul>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;color: black;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"display: none;\"><\/span><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left: 5px solid rgb(222, 198, 251);color: rgb(89, 89, 89);\">\u7ed3\u8bed<\/span><span><\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">AES \u662f\u4e00\u79cd\u9ad8\u6548\u3001\u5b89\u5168\u7684\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\uff0c\u901a\u8fc7\u4e00\u7cfb\u5217\u590d\u6742\u7684\u8f6e\u64cd\u4f5c\u6765\u786e\u4fdd\u6570\u636e\u7684\u4fdd\u5bc6\u6027\u548c\u5b8c\u6574\u6027\u3002\u7406\u89e3 AES \u7684\u5de5\u4f5c\u539f\u7406\uff0c\u6709\u52a9\u4e8e\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u6b63\u786e\u548c\u5b89\u5168\u5730\u4f7f\u7528 AES \u52a0\u5bc6\u7b97\u6cd5\uff0c\u4fdd\u62a4\u654f\u611f\u6570\u636e\u7684\u5b89\u5168\u3002<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0cAES \u901a\u5e38\u4e0e\u5176\u4ed6\u5b89\u5168\u63aa\u65bd\uff08\u5982 HMAC\u3001RSA \u548c HTTPS\uff09\u7ed3\u5408\u4f7f\u7528\uff0c\u4ee5\u63d0\u4f9b\u5168\u9762\u7684\u6570\u636e\u5b89\u5168\u4fdd\u62a4\u3002<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e2a\u4eba\u89c2\u70b9\uff0c\u4ec5\u4f9b\u53c2\u8003\uff0c\u5982\u6709\u95ee\u9898\uff0c\u6b22\u8fce\u7559\u8a00\u8ba8\u8bba\u3002<\/p>\n<\/section>\n<p style=\"display: none;\"><mp-style-type data-value=\"3\"><\/mp-style-type><\/p>\n<blockquote>\n<p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7:                 \u6e90\u8bdd\u7f16\u7a0b              <\/p>\n<\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u275d AES\uff08Advanced Encryption Standard\uff0c\u9ad8\u7ea7\u52a0\u5bc6\u6807\u51c6\uff09\u662f\u4e00\u79cd\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u6570\u636e\u52a0\u5bc6\u9886\u57df\u3002\u672c &#8230;<\/p>\n","protected":false},"author":1,"featured_media":6006,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-6017","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223358231-150x150.jpeg","content_first_image":null,"post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223358231-300x127.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223358231.jpeg","post_frist_image":null,"post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223358231-300x127.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223358231.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223358231.jpeg","post_all_images":[],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring Boot","post_date":"2024-08-01","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":622,"next_post_id":5068,"next_post_title":"Spring\u9879\u76ee\u542f\u52a8\u52a0\u901f\uff1a\u4f18\u5316\u7b56\u7565\u5168\u89e3\u6790","previous_post_id":5124,"previous_post_title":"\u9ad8\u5e76\u53d1\u4e0b\u5982\u4f55\u8f7b\u677e\u7684\u4fdd\u8bc1\u63a5\u53e3\u5e42\u7b49\u6027","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=6017"}],"version-history":[{"count":1,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6017\/revisions"}],"predecessor-version":[{"id":6334,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6017\/revisions\/6334"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/6006"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=6017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=6017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=6017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}