{"id":3028,"date":"2018-08-31T10:06:45","date_gmt":"2018-08-31T02:06:45","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3028"},"modified":"2018-08-31T10:06:45","modified_gmt":"2018-08-31T02:06:45","slug":"%e8%b0%b7%e6%ad%8c-tink%ef%bc%88%e5%8a%a0%e5%af%86api%ef%bc%89-%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3028","title":{"rendered":"\u8c37\u6b4c Tink\uff08\u52a0\u5bc6API\uff09 \u6559\u7a0b"},"content":{"rendered":"<p>\n\t\u8c37\u6b4c\u6700\u8fd1\u53c8\u53d1\u5e03\u4e86\u4e00\u4e2a\u65b0\u7684\u5f00\u6e90\u5de5\u5177\u96c6 Tink\u3002Tink \u662f\u4e00\u4e2a\u591a\u8bed\u8a00\uff0c\u8de8\u5e73\u53f0\u7684\u5e93\uff0c\u63d0\u4f9b\u5b89\u5168\uff0c\u6613\u4e8e\u6b63\u786e\u4f7f\u7528\u548c\u96be\u4ee5\u6ee5\u7528\u7684\u52a0\u5bc6 API\u3002\u6211\u9884\u6d4b\u5b83\u53ef\u80fd\u4f1a\u706b\u8d77\u6765\uff0c\u6240\u4ee5\u5c31\u5148\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u5b83\u7684\u7528\u6cd5\u3002\n<\/p>\n<p>\n\tTink \u9075\u5faa Apache \u7684 2.0 \u5f00\u6e90\u534f\u8bae\u3002Tink \u5e76\u4e0d\u662f\u5b98\u65b9\u652f\u6301\u7684 Google \u4ea7\u54c1\u3002\u800c\u662f\u7531 Google \u7684\u4e00\u7fa4\u5bc6\u7801\u5b66\u5bb6\u548c\u5b89\u5168\u5de5\u7a0b\u5e08\u7f16\u5199\u7684\u52a0\u5bc6\u5e93\u3002\n<\/p>\n<p>\n\tTink \u7ed3\u5408\u4e86 Google \u4ea7\u54c1\u56e2\u961f\u7684\u4e30\u5bcc\u7ecf\u9a8c\uff0c\u4fee\u590d\u4e86\u73b0\u5b9e\u5f00\u53d1\u3001\u90e8\u7f72\u3001\u6d4b\u8bd5\u4e2d\u7684\u4e00\u4e9b\u5f31\u70b9\uff0c\u5e76\u63d0\u4f9b\u4e86\u53ef\u4ee5\u5b89\u5168\u4f7f\u7528\u800c\u65e0\u9700\u52a0\u5bc6\u80cc\u666f\u7684\u7b80\u5355 API\u3002\n<\/p>\n<p>\n\tTink \u63d0\u4f9b\u7684\u5b89\u5168 API \u6613\u4e8e\u6b63\u786e\u4f7f\u7528\u4e14\u96be\u4ee5\u6ee5\u7528\u3002\u5b83\u901a\u8fc7\u4ee5\u7528\u6237\u4e3a\u4e2d\u5fc3\u7684\u8bbe\u8ba1\uff0c\u4ed4\u7ec6\u7684\u5b9e\u65bd\u548c\u4ee3\u7801\u5ba1\u67e5\u4ee5\u53ca\u5e7f\u6cdb\u7684\u6d4b\u8bd5\u6765\u51cf\u5c11\u5e38\u89c1\u7684\u52a0\u5bc6\u9677\u9631\u3002\u5728\u8c37\u6b4c\uff0cTink \u5df2\u88ab\u7528\u4e8e\u4fdd\u62a4\u8bb8\u591a\u4ea7\u54c1\u7684\u6570\u636e\uff0c\u5982 AdMob\uff0cGoogle Pay\uff0cGoogle Assistant\uff0cFirebase\uff0cAndroid Search App \u7b49\u3002\n<\/p>\n<h2>\n\t\u5feb\u901f\u5f00\u59cb<br \/>\n<\/h2>\n<p>\n\t\u5728\u4f7f\u7528 Tink \u4e4b\u524d\u63a8\u8350\u5927\u5bb6\u5148\u5b89\u88c5 <font><font><a href=\"https:\/\/docs.bazel.build\/versions\/master\/install.html\" rel=\"nofollow\">Bazel<\/a>\u3002\u7136\u540e\u6267\u884c\u4e0b\u9762\u7684&nbsp;Bazel \u547d\u4ee4\u5373\u53ef\u770b\u5230\u6784\u5efa\u540e\u7684\u8fd0\u884c\u6548\u679c\uff1a<\/font><\/font>\n<\/p>\n<pre class=\"brush:bash;\">\r\ngit clone https:\/\/github.com\/google\/tink\r\ncd tink\r\nbazel build ...\r\necho foo &gt; foo.txt\r\n.\/bazel-bin\/examples\/helloworld\/java\/helloworld encrypt --keyset test.cfg --in foo.txt --out bar.encrypted\r\n.\/bazel-bin\/examples\/helloworld\/java\/helloworld decrypt --keyset test.cfg --in bar.encrypted --out foo2.txt\r\ncat foo2.txt<\/pre>\n<p>\n\tTink\u901a\u8fc7\u6240\u8c13\u7684\u57fa\u5143\u6267\u884c\u52a0\u5bc6\u4efb\u52a1\uff0c\u6bcf\u4e2a\u57fa\u5143\u901a\u8fc7\u6307\u5b9a\u57fa\u5143\u529f\u80fd\u7684\u76f8\u5e94\u63a5\u53e3\u6765\u5b9a\u4e49\u3002\u4f8b\u5982\uff0c\u5bf9\u79f0\u5bc6\u94a5\u52a0\u5bc6\u662f\u901a\u8fc7AEAD\u539f\u8bed\uff08\u5e26\u6709\u5173\u8054\u6570\u636e\u7684Authenticated Encryption\uff09\u63d0\u4f9b\u7684\uff0c\u5b83\u652f\u6301\u4e24\u79cd\u64cd\u4f5c\uff1a\n<\/p>\n<ul>\n<li>\n\t\tencrypt(plaintext, associated_data)\uff0c\u52a0\u5bc6\u7ed9\u5b9a\u7684plaintext \uff08\u4f7f\u7528associated_data\u53e6\u5916\u7684AEAD\u8f93\u5165\uff09\u5e76\u8fd4\u56de\u751f\u6210\u7684\u5bc6\u6587\n\t<\/li>\n<li>\n\t\tdecrypt(ciphertext, associated_data)\uff0c\u89e3\u5bc6\u7ed9\u5b9a\u7684 ciphertext\uff08\u4f7f\u7528associated_data\u53e6\u5916\u7684AEAD\u8f93\u5165\uff09\u5e76\u8fd4\u56de\u7ed3\u679c\u660e\u6587\n\t<\/li>\n<\/ul>\n<p>\n\t\u5728\u53ef\u4f7f\u7528\u57fa\u5143\u7684\u5b9e\u73b0\u4e4b\u524d\uff0c\u5fc5\u987b\u5728\u8fd0\u884c\u65f6\u4f7f\u7528 Tink \u6ce8\u518c\u5b83\u4eec\uff0c\u4ee5\u4fbf Tink &ldquo;\u77e5\u9053&rdquo;\u6240\u9700\u7684\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5728Tink\u4e2d\u6ce8\u518c\u6240\u6709\u57fa\u5143\u7684\u6240\u6709\u5b9e\u73b0\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\nimport com.google.crypto.tink.config.TinkConfig;\r\n\r\nTinkConfig.register();<\/pre>\n<p>\n\t\u5728\u6ce8\u518c\u4e86\u57fa\u5143\u7684\u5b9e\u73b0\u4e4b\u540e\uff0cTink\u7684\u57fa\u672c\u7528\u6cd5\u5206\u4e09\u6b65\u8fdb\u884c\uff1a\n<\/p>\n<ol>\n<li>\n\t\t\u52a0\u8f7d\u6216\u751f\u6210\u52a0\u5bc6\u5bc6\u94a5\u6750\u6599\uff08Keyset\u4ee5Tink\u672f\u8bed\u8868\u793a\uff09\u3002\n\t<\/li>\n<li>\n\t\t\u4f7f\u7528\u5bc6\u94a5\u6750\u6599\u83b7\u53d6\u6240\u9009\u57fa\u5143\u7684\u5b9e\u4f8b\u3002\n\t<\/li>\n<li>\n\t\t\u4f7f\u7528\u8be5\u539f\u8bed\u6765\u5b8c\u6210\u52a0\u5bc6\u4efb\u52a1\u3002\n\t<\/li>\n<\/ol>\n<p>\n\t\u4ee5\u4e0b\u662f\u5728 Java \u4e2d\u4f7f\u7528 Tink \u52a0\u5bc6\u6216\u89e3\u5bc6\u65f6\u7684\u6b65\u9aa4\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\nimport com.google.crypto.tink.Aead;\r\nimport com.google.crypto.tink.KeysetHandle;\r\nimport com.google.crypto.tink.aead.AeadFactory;\r\nimport com.google.crypto.tink.aead.AeadKeyTemplates;\r\n\r\n\/\/ 1.\u751f\u6210\u5bc6\u94a5\u6750\u6599\u3002\r\nKeysetHandle keysetHandle = KeysetHandle.generateNew(\r\n    AeadKeyTemplates.AES128_GCM);\r\n\r\n\/\/ 2.\u83b7\u53d6 Aead \u539f\u8bed\r\nAead aead = AeadFactory.getPrimitive(keysetHandle);\r\n\r\n\/\/ 3.\u4f7f\u7528\u539f\u8bed\u3002\r\nbyte[] ciphertext = aead.encrypt(plaintext, aad);<\/pre>\n<p>\n\tTink \u76ee\u524d\u9664\u4e86\u652f\u6301 java \u5916\uff0c\u8fd8\u652f\u6301 Android\u3001C++\u3001Obj-C\u3002\u76ee\u524d\u6700\u65b0\u7248\u672c\u662f 2018-08-09 \u53d1\u5e03\u7684 1.2.0\u3002\n<\/p>\n<h2>\n\t\u53c2\u8003\u8d44\u6599<br \/>\n<\/h2>\n<ul>\n<li>\n\t\t<a href=\"https:\/\/github.com\/google\/tink\" name=\"tink\" target=\"_blank\" title=\"tink\">https:\/\/github.com\/google\/tink<\/a>\n\t<\/li>\n<\/ul>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3028\">\u8c37\u6b4c Tink\uff08\u52a0\u5bc6API\uff09 \u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u8c37\u6b4c\u6700\u8fd1\u53c8\u53d1\u5e03\u4e86\u4e00\u4e2a\u65b0\u7684\u5f00\u6e90\u5de5\u5177\u96c6 Tink\u3002Tink \u662f\u4e00\u4e2a\u591a\u8bed\u8a00\uff0c\u8de8\u5e73\u53f0\u7684\u5e93\uff0c\u63d0\u4f9b\u5b89\u5168\uff0c\u6613\u4e8e\u6b63\u786e\u4f7f\u7528\u548c\u96be\u4ee5 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[871,971,688,1668,684],"class_list":["post-3028","post","type-post","status-publish","format-standard","hentry","category-java","tag-idea","tag-shiro-","tag-sql","tag-tink","tag-684"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3028"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3028\/revisions"}],"predecessor-version":[{"id":3029,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3028\/revisions\/3029"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}