{"id":2856,"date":"2025-08-27T14:12:21","date_gmt":"2025-08-27T06:12:21","guid":{"rendered":"https:\/\/www.xfan.top\/?p=2856"},"modified":"2025-08-27T16:31:14","modified_gmt":"2025-08-27T08:31:14","slug":"crypto-randomuuid%e4%b8%8ecrypto%e7%9a%84https-localhost%e9%99%90%e5%88%b6","status":"publish","type":"post","link":"https:\/\/www.xfan.top\/index.php\/2025\/08\/27\/2856\/","title":{"rendered":"crypto.randomUUID()\u4e0ecrypto\u7684HTTPS \/ localhost\u9650\u5236"},"content":{"rendered":"<p>\u4f7f\u7528127.0.0.1\u6216\u5c40\u57df\u7f51IP\u76f4\u63a5\u8bbf\u95ee\u7684\u9875\u9762\u4e2d\uff0c\u65e0\u6cd5\u4f7f\u7528<code>crypto.randomUUID()<\/code>\u3002<br \/>\n\u5176\u6839\u672c\u539f\u56e0\u662f<code>crypto.randomUUID()<\/code>\u8c03\u7528\u4e86<code>crypto.getRandomValues(array)<\/code>\u6765\u751f\u6210\u4f2a\u968f\u673a\u6570\uff0c\u800c<code>crypto.getRandomValues<\/code>\u6709\u8f83\u9ad8\u7684\u5b89\u5168\u8981\u6c42\uff0c\u5fc5\u987b\u5728 HTTPS \/ localhost \u73af\u5883\u4e2d\u624d\u53ef\u4f7f\u7528\u3002\u7406\u7531\u5927\u81f4\u53ef\u4ee5\u5206\u4e3a\u4e24\u4e2a\u5c42\u9762\uff1a<\/p>\n<h4>\u4f20\u8f93\u5b89\u5168<\/h4>\n<p>\u5728 HTTP \u73af\u5883\u4e2d\uff1a<\/p>\n<ul>\n<li>\u6240\u6709\u8bf7\u6c42\u3001\u54cd\u5e94\u90fd\u53ef\u80fd\u88ab\u4e2d\u95f4\u4eba\u653b\u51fb\u7be1\u6539\u3002<\/li>\n<li>\u5373\u4f7f\u9875\u9762\u7528<code>crypto.getRandomValues()<\/code>\u751f\u6210\u4e86\u5f3a\u968f\u673a\u6570\uff08\u6bd4\u5982\u505a\u7b7e\u540d\u3001HMAC\u3001Token\uff09\uff0c\u653b\u51fb\u8005\u4e5f\u53ef\u4ee5\u76f4\u63a5\u62e6\u622a\u6216\u66ff\u6362\u968f\u673a\u503c\uff0c\u5bfc\u81f4\u7b7e\u540d\u548c\u6821\u9a8c\u5b8c\u5168\u5931\u6548\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a<br \/>\n\u4f60\u7528\u968f\u673a\u6570\u751f\u6210 Session Token \u2192 \u4f20\u8f93\u5728 HTTP \u4e2d \u2192 \u4e2d\u95f4\u4eba\u770b\u5230\u5e76\u7be1\u6539 \u2192 Token \u5931\u53bb\u610f\u4e49\u3002<br \/>\n\u5373\u4f7f\u7b97\u6cd5\u672c\u8eab\u5b89\u5168\uff0c<strong>\u4e0d\u5b89\u5168\u7684\u4f20\u8f93\u8ba9\u5b89\u5168\u6027\u5f52\u96f6<\/strong>\u3002<\/p>\n<p>\u6240\u4ee5\u6d4f\u89c8\u5668\u89c4\u5b9a\uff1a<br \/>\n\u5b89\u5168\u4f20\u8f93 (HTTPS\/localhost) \u624d\u80fd\u8c03\u7528 Web Crypto API\uff0c<strong>\u907f\u514d\u5f00\u53d1\u8005\u5728 HTTP \u4e0b\u4ea7\u751f\u201c\u4f2a\u5b89\u5168\u611f\u201d<\/strong>\u3002<\/p>\n<h4>\u64cd\u4f5c\u7cfb\u7edf\u5e95\u5c42\u968f\u673a\u6570\u6e90<\/h4>\n<p><code>crypto.getRandomValues()<\/code>\u4e0d\u662f\u5728JavaScript\u73af\u5883\u8ba1\u7b97\u5f97\u51fa\u7ed3\u679c\u7684\uff0c\u800c\u662f\u8c03\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684CSPRNG\uff08Cryptographically Secure PseudoRandom Number Generator\uff0c\u5bc6\u7801\u5b66\u5b89\u5168\u4f2a\u968f\u673a\u6570\u751f\u6210\u5668\uff09\uff1a<\/p>\n<blockquote>\n<p>JS \u8c03\u7528 crypto.getRandomValues()<br \/>\n\u2193<br \/>\n\u6d4f\u89c8\u5668 JS \u5f15\u64ce (V8 \/ SpiderMonkey \/ JavaScriptCore)<br \/>\n\u2193<br \/>\nC++ \u5c42\u5c01\u88c5 (Chromium: base::RandBytes)<br \/>\n\u2193<br \/>\n\u64cd\u4f5c\u7cfb\u7edf API (BCryptGenRandom \/ getrandom \/ SecRandomCopyBytes)<br \/>\n\u2193<br \/>\n\u64cd\u4f5c\u7cfb\u7edf\u7684 CSPRNG \u71b5\u6c60<\/p>\n<\/blockquote>\n<p>\u8fd9\u4e9b\u5e95\u5c42\u71b5\u6c60\u4f1a\u6536\u96c6\u786c\u4ef6\u566a\u58f0\u3001\u65f6\u95f4\u3001\u7cfb\u7edf\u4e8b\u4ef6\uff0c\u4fdd\u8bc1\u4e0d\u53ef\u9884\u6d4b\u3002<br \/>\n\u4e00\u65e6\u968f\u673a\u6570\u751f\u6210\u88ab\u52ab\u6301\uff0c\u88ab\u66ff\u6362\u6210\u4f2a\u968f\u673a\u6570\uff0c\u4f1a\u5bfc\u81f4\uff1a<\/p>\n<blockquote>\n<p>\u5bc6\u94a5\u53ef\u9884\u6d4b \u2192 \u52a0\u5bc6\u5931\u6548<br \/>\n\u7b7e\u540d k \u91cd\u590d \u2192 \u79c1\u94a5\u6cc4\u9732<br \/>\nToken \/ Session \u53ef\u9884\u6d4b \u2192 \u8eab\u4efd\u4f2a\u9020<\/p>\n<\/blockquote>\n<p>\u800c\u5728HTTPS\u73af\u5883\u4e2d\uff0c\u5f00\u53d1\u8005\u53ef\u4e25\u683c\u9650\u5236\u7b2c\u4e09\u65b9JS\u811a\u672c\u7684\u52a0\u8f7d\uff0c\u51cf\u5c11\u5728JS\u5c42\u88abHook\u52ab\u6301\u7684\u98ce\u9669<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528127.0.0.1\u6216\u5c40\u57df\u7f51IP\u76f4\u63a5\u8bbf\u95ee\u7684\u9875\u9762\u4e2d\uff0c\u65e0\u6cd5\u4f7f\u7528crypto.randomUUID()\u3002 \u5176\u6839\u672c\u539f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2856","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/comments?post=2856"}],"version-history":[{"count":5,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2856\/revisions"}],"predecessor-version":[{"id":2861,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/posts\/2856\/revisions\/2861"}],"wp:attachment":[{"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/media?parent=2856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/categories?post=2856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xfan.top\/index.php\/wp-json\/wp\/v2\/tags?post=2856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}