{"id":48976,"date":"2024-12-02T16:38:14","date_gmt":"2024-12-02T08:38:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48976\/"},"modified":"2024-12-02T16:38:14","modified_gmt":"2024-12-02T08:38:14","slug":"lithe-crypt%ef%bc%9a%e7%ae%80%e5%8c%96-php-%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e4%b8%ad%e7%9a%84%e5%8a%a0%e5%af%86%e6%8a%80%e6%9c%af-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48976\/","title":{"rendered":"Lithe Crypt\uff1a\u7b80\u5316 PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u52a0\u5bc6\u6280\u672f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Lithe Crypt\uff1a\u7b80\u5316 PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u52a0\u5bc6\u6280\u672f<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aLithe Crypt\uff1a\u7b80\u5316 PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u52a0\u5bc6\u6280\u672f\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241105\/17307979716729e1936242a.jpg\" class=\"aligncenter\" title=\"Lithe Crypt\uff1a\u7b80\u5316 PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u52a0\u5bc6\u6280\u672f\u63d2\u56fe\" alt=\"Lithe Crypt\uff1a\u7b80\u5316 PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u52a0\u5bc6\u6280\u672f\u63d2\u56fe\" \/><\/p>\n<p><strong>lithe crypt<\/strong> \u662f php \u4e2d\u7684\u4e00\u4e2a\u7b80\u5355\u7684\u52a0\u5bc6\u548c\u89e3\u5bc6\u5b9e\u7528\u7a0b\u5e8f\uff0c\u65e8\u5728\u4e0e lithe \u6846\u67b6\u914d\u5408\u4f7f\u7528\u3002\u5b83\u4f7f\u7528 aes-256-cbc \u7b97\u6cd5\u8fdb\u884c\u5b89\u5168\u6570\u636e\u5904\u7406\u3002<\/p>\n<h2> \u5b89\u88c5 <\/h2>\n<p>\u8981\u5b89\u88c5 lithe crypt \u8f6f\u4ef6\u5305\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 composer\u3002\u5982\u679c\u60a8\u5c1a\u672a\u5b89\u88c5\uff0c\u8bf7\u786e\u4fdd composer \u5728\u60a8\u7684\u7cfb\u7edf\u4e0a\u53ef\u7528\u3002\u7136\u540e\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>composer require lithemod\/crypt\n<\/pre>\n<h3> \u8981\u6c42 <\/h3>\n<ul>\n<li>php 8 \u6216\u66f4\u9ad8\u7248\u672c<\/li>\n<li>\u5728 php \u5b89\u88c5\u4e2d\u542f\u7528 openssl \u6269\u5c55<\/li>\n<\/ul>\n<h2> \u4f7f\u7528 <\/h2>\n<h3> \u52a0\u8f7d\u73af\u5883\u53d8\u91cf <\/h3>\n<p>\u5728\u4f7f\u7528 crypt \u7c7b\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u52a0\u8f7d\u73af\u5883\u53d8\u91cf\u3002\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u52a0\u8f7d\u60a8\u7684 .env \u6587\u4ef6\uff1a<\/p>\n<pre>use lithe\\support\\env;\n\n\/\/ carregar vari\u00e1veis de ambiente\nenv::load(__dir__); \/\/ ajuste o caminho conforme necess\u00e1rio\n<\/pre>\n<h3> \u8bbe\u7f6eapp_key <\/h3>\n<p>\u786e\u4fdd\u5df2\u8bbe\u7f6e app_key \u73af\u5883\u53d8\u91cf\u3002\u6b64\u5bc6\u94a5\u5fc5\u987b\u662f 32 \u5b57\u8282\u7684 base64 \u7f16\u7801\u5b57\u7b26\u4e32\u3002\u60a8\u53ef\u4ee5\u5728 .env \u6587\u4ef6\u4e2d\u914d\u7f6e\u5b83\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5728\u670d\u52a1\u5668\u73af\u5883\u4e2d\u914d\u7f6e\u5b83\u3002<\/p>\n<p>\u6709\u6548\u7684 base64 \u5bc6\u94a5\u793a\u4f8b\uff1a<\/p>\n<pre>yxnkzmfnc2rhc2rmywdlcybhc2rmywdlcybhyxnkzmfnc2q=\n<\/pre>\n<h3> \u52a0\u5bc6\u6570\u636e <\/h3>\n<p>\u8981\u52a0\u5bc6\u6570\u636e\uff0c\u8bf7\u4f7f\u7528 crypt \u7c7b\u7684 encrypt \u65b9\u6cd5\u3002\u60a8\u8fd8\u53ef\u4ee5\u6307\u5b9a\u662f\u5426\u8981\u4f7f\u7528\u56fa\u5b9aiv\uff08\u521d\u59cb\u5316\u5411\u91cf\uff09\u8fdb\u884c\u52a0\u5bc6\uff1a<\/p>\n<pre>use lithe\\support\\security\\crypt;\n\n$data = \"dados sens\u00edveis\";\n\n\/\/ criptografar sem iv fixo\n$encrypted = crypt::encrypt($data);\necho \"dados criptografados: \" . $encrypted;\n\n\/\/ criptografar com iv fixo (\u00fatil para valores \u00fanicos como e-mails)\n$encryptedwithsameiv = crypt::encrypt($data, true);\necho \"dados criptografados com iv fixo: \" . $encryptedwithsameiv;\n<\/pre>\n<h3> \u89e3\u5bc6\u6570\u636e <\/h3>\n<p>\u8981\u89e3\u5bc6\u4e4b\u524d\u52a0\u5bc6\u7684\u6570\u636e\uff0c\u8bf7\u4f7f\u7528decrypt\u65b9\u6cd5\u3002\u60a8\u5fc5\u987b\u6307\u5b9a\u4e0e\u52a0\u5bc6\u65f6\u4f7f\u7528\u7684\u53c2\u6570\u76f8\u540c\u7684\u53c2\u6570\uff0c\u4ee5\u786e\u4fdd\u6b63\u786e\u89e3\u5bc6\uff1a<\/p>\n<pre>use lithe\\support\\security\\crypt;\n\n\/\/ descriptografar sem iv fixo\n$decrypted = crypt::decrypt($encrypted);\necho \"dados descriptografados: \" . $decrypted;\n\n\/\/ descriptografar com iv fixo\n$decryptedwithsameiv = crypt::decrypt($encryptedwithsameiv, true, $data);\necho \"dados descriptografados com iv fixo: \" . $decryptedwithsameiv;\n<\/pre>\n<h3> \u5f02\u5e38\u5904\u7406 <\/h3>\n<p>\u5982\u679c app_key \u672a\u5b9a\u4e49\u6216\u65e0\u6548\uff0ccrypt \u7c7b\u5c06\u629b\u51fa cryptexception\u3002\u5fc5\u987b\u5728\u4ee3\u7801\u4e2d\u5904\u7406\u6b64\u5f02\u5e38\u4ee5\u907f\u514d\u610f\u5916\u9519\u8bef\uff1a<\/p>\n<pre>use Lithe\\Exceptions\\Encryption\\CryptException;\n\ntry {\n    $encrypted = Crypt::encrypt($data);\n    \/\/ Descriptografar sem IV fixo\n    $decrypted = Crypt::decrypt($encrypted);\n} catch (CryptException $e) {\n    echo \"Erro de Criptografia: \" . $e-&gt;getMessage();\n}\n<\/pre>\n<h2> \u6700\u540e\u7684\u8003\u8651\u56e0\u7d20 <\/h2>\n<p><strong>lithe crypt<\/strong> \u63d0\u4f9b\u4e86\u4e00\u79cd\u5b9e\u7528\u4e14\u5b89\u5168\u7684\u65b9\u6cd5\u6765\u5904\u7406 php \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u6570\u636e\u52a0\u5bc6\u548c\u89e3\u5bc6\u3002\u901a\u8fc7\u5b9e\u65bd aes-256-cbc \u7b97\u6cd5\u4ee5\u53ca\u4e0e lithe \u6846\u67b6\u7684\u8f7b\u677e\u96c6\u6210\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u4fdd\u62a4\u60a8\u7684\u6570\u636e\u3002\u5c1d\u8bd5\u4e00\u4e0b\uff0c\u770b\u770b\u5b83\u5982\u4f55\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u5b89\u5168\u6027\uff01<\/p>\n<p>\u5982\u679c\u60a8\u6709\u4efb\u4f55\u7591\u95ee\u6216\u5efa\u8bae\uff0c\u8bf7\u968f\u65f6\u5728\u4e0b\u9762\u8bc4\u8bba\uff01<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aLithe Crypt\uff1a\u7b80\u5316 PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u52a0\u5bc6\u6280\u672f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lithe Crypt\uff1a\u7b80\u5316 PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u52a0\u5bc6\u6280\u672f \u6536\u85cf \u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60\u6587\u7ae0\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765\u300aLithe Crypt\uff1a\u7b80\u5316 PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u52a0\u5bc6\u6280\u672f\u300b\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01 lithe crypt \u662f php \u4e2d\u7684\u4e00\u4e2a\u7b80\u5355\u7684\u52a0\u5bc6\u548c\u89e3\u5bc6\u5b9e\u7528\u7a0b\u5e8f\uff0c\u65e8\u5728\u4e0e lithe \u6846\u67b6\u914d\u5408\u4f7f\u7528\u3002\u5b83\u4f7f\u7528 aes-256-cbc \u7b97\u6cd5\u8fdb\u884c\u5b89\u5168\u6570\u636e\u5904\u7406\u3002 \u5b89\u88c5 \u8981\u5b89\u88c5 lithe crypt \u8f6f\u4ef6\u5305\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 composer\u3002\u5982\u679c\u60a8\u5c1a\u672a\u5b89\u88c5\uff0c\u8bf7\u786e\u4fdd composer \u5728\u60a8\u7684\u7cfb\u7edf\u4e0a\u53ef\u7528\u3002\u7136\u540e\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a composer require lithemod\/crypt \u8981\u6c42 php 8 \u6216\u66f4\u9ad8\u7248\u672c \u5728 php \u5b89\u88c5\u4e2d\u542f\u7528 openssl \u6269\u5c55 \u4f7f\u7528 \u52a0\u8f7d\u73af\u5883\u53d8\u91cf \u5728\u4f7f\u7528 crypt \u7c7b\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u52a0\u8f7d\u73af\u5883\u53d8\u91cf\u3002\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u52a0\u8f7d\u60a8\u7684 .env \u6587\u4ef6\uff1a use lithe\\support\\env; \/\/ carregar vari\u00e1veis de ambiente env::load(__dir__); \/\/ ajuste [&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-48976","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48976","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=48976"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48976\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}