{"id":3660,"date":"2025-03-01T13:19:50","date_gmt":"2025-03-01T04:19:50","guid":{"rendered":"https:\/\/blue-bear.jp\/kb\/?p=3660"},"modified":"2025-03-01T13:19:51","modified_gmt":"2025-03-01T04:19:51","slug":"python%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e4%bf%9d%e8%ad%b7%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae%e3%83%88%e3%83%bc%e3%82%af%e3%83%8a%e3%82%a4%e3%82%bc%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/python%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e4%bf%9d%e8%ad%b7%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae%e3%83%88%e3%83%bc%e3%82%af%e3%83%8a%e3%82%a4%e3%82%bc%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92\/","title":{"rendered":"Python\u3067\u30c7\u30fc\u30bf\u4fdd\u8b77\u306e\u305f\u3081\u306e\u30c8\u30fc\u30af\u30ca\u30a4\u30bc\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u88c5\u3059\u308b"},"content":{"rendered":"\n<p>\u30c7\u30fc\u30bf\u4fdd\u8b77\u306f\u3001\u30d7\u30e9\u30a4\u30d0\u30b7\u30fc\u3084\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u306e\u89b3\u70b9\u304b\u3089\u91cd\u8981\u306a\u8ab2\u984c\u3067\u3059\u3002\u7279\u306b\u3001\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u60c5\u5831\u306a\u3069\u306e\u6a5f\u5bc6\u30c7\u30fc\u30bf\u3092\u6271\u3046\u969b\u306b\u306f\u3001**\u30c8\u30fc\u30af\u30ca\u30a4\u30bc\u30fc\u30b7\u30e7\u30f3\uff08Tokenization\uff09<strong>\u3068<\/strong>\u6697\u53f7\u5316\uff08Encryption\uff09**\u306e\u3069\u3061\u3089\u3092\u63a1\u7528\u3059\u308b\u304b\u3092\u9069\u5207\u306b\u5224\u65ad\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u672c\u8a18\u4e8b\u3067\u306f\u3001\u305d\u308c\u305e\u308c\u306e\u6280\u8853\u306e\u9055\u3044\u3001\u30e1\u30ea\u30c3\u30c8\u30fb\u30c7\u30e1\u30ea\u30c3\u30c8\u3001\u305d\u3057\u3066\u5177\u4f53\u7684\u306a\u5b9f\u88c5\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. \u30c8\u30fc\u30af\u30ca\u30a4\u30bc\u30fc\u30b7\u30e7\u30f3\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>\u30c8\u30fc\u30af\u30ca\u30a4\u30bc\u30fc\u30b7\u30e7\u30f3\u306f\u3001<strong>\u6a5f\u5bc6\u30c7\u30fc\u30bf\u3092\u4e00\u610f\u306e\u30c8\u30fc\u30af\u30f3\uff08\u8b58\u5225\u5b50\uff09\u306b\u7f6e\u304d\u63db\u3048\u308b<\/strong>\u6280\u8853\u3067\u3059\u3002\u5143\u306e\u30c7\u30fc\u30bf\u306f\u4fdd\u5b58\u305b\u305a\u3001\u5b89\u5168\u306a\u30de\u30c3\u30d4\u30f3\u30b0\u30c6\u30fc\u30d6\u30eb\u306b\u306e\u307f\u8a18\u9332\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30c8\u30fc\u30af\u30f3\u3060\u3051\u3067\u306f\u5143\u306e\u30c7\u30fc\u30bf\u3092\u7279\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u305a\u3001\u4e07\u304c\u4e00\u30c7\u30fc\u30bf\u304c\u6f0f\u6d29\u3057\u3066\u3082\u5b89\u5168\u6027\u304c\u4fdd\u305f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 \u30c8\u30fc\u30af\u30ca\u30a4\u30bc\u30fc\u30b7\u30e7\u30f3\u306e\u30e1\u30ea\u30c3\u30c8<\/h3>\n\n\n\n<ul>\n<li><strong>\u5143\u30c7\u30fc\u30bf\u304c\u4e0d\u8981<\/strong>\uff1a\u30c8\u30fc\u30af\u30f3\u306f\u5143\u306e\u30c7\u30fc\u30bf\u306b\u4f9d\u5b58\u305b\u305a\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u5185\u3067\u306e\u307f\u7ba1\u7406\u3067\u304d\u308b\u3002<\/li>\n\n\n\n<li><strong>\u975e\u53ef\u9006\u6027<\/strong>\uff1a\u9069\u5207\u306a\u30de\u30c3\u30d4\u30f3\u30b0\u30c6\u30fc\u30d6\u30eb\u304c\u306a\u3051\u308c\u3070\u3001\u30c8\u30fc\u30af\u30f3\u304b\u3089\u5143\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3067\u304d\u306a\u3044\u3002<\/li>\n\n\n\n<li><strong>\u30b3\u30f3\u30d7\u30e9\u30a4\u30a2\u30f3\u30b9\u5bfe\u5fdc<\/strong>\uff1aPCI DSS\uff08\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u696d\u754c\u306e\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u57fa\u6e96\uff09\u306b\u9069\u5408\u3057\u3084\u3059\u3044\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 \u30c8\u30fc\u30af\u30ca\u30a4\u30bc\u30fc\u30b7\u30e7\u30f3\u306e\u30c7\u30e1\u30ea\u30c3\u30c8<\/h3>\n\n\n\n<ul>\n<li><strong>\u30de\u30c3\u30d4\u30f3\u30b0\u30c6\u30fc\u30d6\u30eb\u306e\u7ba1\u7406\u304c\u5fc5\u8981<\/strong>\uff1a\u5143\u30c7\u30fc\u30bf\u3068\u306e\u5bfe\u5fdc\u3092\u8a18\u9332\u3059\u308b\u305f\u3081\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u5fc5\u8981\u3002<\/li>\n\n\n\n<li><strong>\u30c7\u30fc\u30bf\u91cf\u304c\u5897\u3048\u308b<\/strong>\uff1a\u4e00\u610f\u306e\u30c8\u30fc\u30af\u30f3\u3092\u7ba1\u7406\u3059\u308b\u305f\u3081\u306b\u8ffd\u52a0\u306e\u30b9\u30c8\u30ec\u30fc\u30b8\u304c\u5fc5\u8981\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">1.3 Python\u306b\u3088\u308b\u30c8\u30fc\u30af\u30ca\u30a4\u30bc\u30fc\u30b7\u30e7\u30f3\u5b9f\u88c5\u4f8b<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import uuid\n\ntoken_table = {}  # \u30c8\u30fc\u30af\u30f3\u3068\u5143\u30c7\u30fc\u30bf\u306e\u5bfe\u5fdc\u8868\n\ndef tokenize_string(input_string):\n    if input_string in token_table:\n        return token_table&#91;input_string]\n    token = str(uuid.uuid4())  # \u4e00\u610f\u306e\u30c8\u30fc\u30af\u30f3\u3092\u751f\u6210\n    token_table&#91;input_string] = token\n    return token\n\ndef detokenize_string(token):\n    for original, stored_token in token_table.items():\n        if stored_token == token:\n            return original\n    raise ValueError(\"Token not found\")\n\n# \u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\nstrings_to_tokenize = &#91;\"4111111111111111\", \"5500000000000004\", \"340000000000009\"]\n\n# \u30c8\u30fc\u30af\u30f3\u5316\ntokenized_strings = &#91;tokenize_string(s) for s in strings_to_tokenize]\nprint(\"\u30c8\u30fc\u30af\u30f3\u5316\u3055\u308c\u305f\u30c7\u30fc\u30bf:\", tokenized_strings)\n\n# \u5fa9\u53f7\u5316\noriginal_strings = &#91;detokenize_string(t) for t in tokenized_strings]\nprint(\"\u5143\u30c7\u30fc\u30bf:\", original_strings)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u6697\u53f7\u5316\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>\u6697\u53f7\u5316\u306f\u3001<strong>\u6a5f\u5bc6\u30c7\u30fc\u30bf\u3092\u9375\uff08Key\uff09\u3092\u4f7f\u3063\u3066\u5909\u63db\u3057\u3001\u5fa9\u53f7\u5316\uff08\u5fa9\u5143\uff09\u304c\u53ef\u80fd\u306a\u5f62\u3067\u4fdd\u5b58\u3059\u308b\u6280\u8853<\/strong>\u3067\u3059\u3002\u6697\u53f7\u5316\u3092\u884c\u3046\u3053\u3068\u3067\u3001\u30c7\u30fc\u30bf\u304c\u5b89\u5168\u306b\u4fdd\u5b58\u3055\u308c\u3001\u9069\u5207\u306a\u9375\u3092\u6301\u3064\u30e6\u30fc\u30b6\u30fc\u3060\u3051\u304c\u5143\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 \u6697\u53f7\u5316\u306e\u30e1\u30ea\u30c3\u30c8<\/h3>\n\n\n\n<ul>\n<li><strong>\u30c7\u30fc\u30bf\u306e\u5b8c\u5168\u6027<\/strong>\uff1a\u6697\u53f7\u5316\u3055\u308c\u305f\u30c7\u30fc\u30bf\u306f\u5fa9\u53f7\u53ef\u80fd\u3067\u3042\u308a\u3001\u5143\u306e\u30c7\u30fc\u30bf\u3068\u4e00\u81f4\u3059\u308b\u3002<\/li>\n\n\n\n<li><strong>\u3088\u308a\u9ad8\u5ea6\u306a\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3<\/strong>\uff1a\u9069\u5207\u306a\u9375\u7ba1\u7406\u3092\u884c\u3046\u3053\u3068\u3067\u3001\u653b\u6483\u8005\u304c\u30c7\u30fc\u30bf\u3092\u89e3\u8aad\u3059\u308b\u306e\u3092\u9632\u3052\u308b\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 \u6697\u53f7\u5316\u306e\u30c7\u30e1\u30ea\u30c3\u30c8<\/h3>\n\n\n\n<ul>\n<li><strong>\u9375\u7ba1\u7406\u304c\u5fc5\u8981<\/strong>\uff1a\u9069\u5207\u306a\u6697\u53f7\u9375\u3092\u7ba1\u7406\u3057\u306a\u3051\u308c\u3070\u3001\u30c7\u30fc\u30bf\u3092\u5fa9\u5143\u3067\u304d\u306a\u304f\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<\/li>\n\n\n\n<li><strong>\u51e6\u7406\u30b3\u30b9\u30c8\u304c\u304b\u304b\u308b<\/strong>\uff1a\u6697\u53f7\u5316\u30fb\u5fa9\u53f7\u5316\u306e\u30d7\u30ed\u30bb\u30b9\u306b\u306f\u8a08\u7b97\u30ea\u30bd\u30fc\u30b9\u3092\u8981\u3059\u308b\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 Python\u306b\u3088\u308b\u6697\u53f7\u5316\u5b9f\u88c5\uff08Fernet\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>from cryptography.fernet import Fernet\n\n# \u56fa\u5b9a\u306e\u6697\u53f7\u9375\uff0832\u30d0\u30a4\u30c8\u306eBase64\u30a8\u30f3\u30b3\u30fc\u30c9\u6587\u5b57\u5217\uff09\nkey = b'V8sJlU0u_LWqDkKo6NqWvJ3P2NCm5O5Oe0jO9iwzFxg='\ncipher = Fernet(key)\n\ndef encrypt_string(input_string):\n    return cipher.encrypt(input_string.encode()).decode()\n\ndef decrypt_string(encrypted_string):\n    return cipher.decrypt(encrypted_string.encode()).decode()\n\n# \u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\noriginal_data = \"4111111111111111\"\n\n# \u6697\u53f7\u5316\nencrypted_data = encrypt_string(original_data)\nprint(\"\u6697\u53f7\u5316\u30c7\u30fc\u30bf:\", encrypted_data)\n\n# \u5fa9\u53f7\u5316\ndecrypted_data = decrypt_string(encrypted_data)\nprint(\"\u5fa9\u53f7\u5316\u30c7\u30fc\u30bf:\", decrypted_data)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u3069\u3061\u3089\u3092\u4f7f\u3046\u3079\u304d\u304b\uff1f<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u9805\u76ee<\/th><th>\u30c8\u30fc\u30af\u30ca\u30a4\u30bc\u30fc\u30b7\u30e7\u30f3<\/th><th>\u6697\u53f7\u5316<\/th><\/tr><\/thead><tbody><tr><td>\u53ef\u9006\u6027<\/td><td>\u3042\u308a\uff08\u30de\u30c3\u30d4\u30f3\u30b0\u30c6\u30fc\u30d6\u30eb\u7d4c\u7531\uff09<\/td><td>\u3042\u308a\uff08\u5fa9\u53f7\u9375\u304c\u3042\u308c\u3070\uff09<\/td><\/tr><tr><td>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3<\/td><td>\u30de\u30c3\u30d4\u30f3\u30b0\u30c6\u30fc\u30d6\u30eb\u3092\u5b88\u308b\u5fc5\u8981\u3042\u308a<\/td><td>\u6697\u53f7\u9375\u306e\u7ba1\u7406\u304c\u91cd\u8981<\/td><\/tr><tr><td>\u8a08\u7b97\u8ca0\u8377<\/td><td>\u4f4e\u3044<\/td><td>\u9ad8\u3044<\/td><\/tr><tr><td>PCI DSS\u9069\u5408<\/td><td>\u3057\u3084\u3059\u3044<\/td><td>\u53ef\u80fd\u3060\u304c\u9069\u5207\u306a\u7ba1\u7406\u304c\u5fc5\u8981<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u307e\u3068\u3081<\/h2>\n\n\n\n<ul>\n<li><strong>\u30c8\u30fc\u30af\u30ca\u30a4\u30bc\u30fc\u30b7\u30e7\u30f3<\/strong>\u306f\u3001\u30c7\u30fc\u30bf\u3092\u5b8c\u5168\u306b\u7f6e\u304d\u63db\u3048\u308b\u624b\u6cd5\u3067\u3042\u308a\u3001\u975e\u53ef\u9006\u7684\u306a\u65b9\u6cd5\u3068\u3057\u3066\u3088\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>\u6697\u53f7\u5316<\/strong>\u306f\u3001\u5143\u30c7\u30fc\u30bf\u3092\u4fdd\u3063\u305f\u307e\u307e\u4fdd\u8b77\u3059\u308b\u65b9\u6cd5\u3067\u3001\u53ef\u9006\u7684\u306a\u7279\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li><strong>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u8981\u4ef6\u3068\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u8981\u4ef6\u306b\u5fdc\u3058\u3066\u3001\u9069\u5207\u306a\u624b\u6cd5\u3092\u9078\u629e\u3059\u308b\u3053\u3068\u304c\u91cd\u8981<\/strong>\u3067\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u7279\u306b\u3001\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u756a\u53f7\u306a\u3069\u306e<strong>\u6c7a\u6e08\u60c5\u5831\u306e\u4fdd\u8b77<\/strong>\u306b\u306fPCI DSS\u6e96\u62e0\u304c\u6c42\u3081\u3089\u308c\u308b\u305f\u3081\u3001\u9069\u5207\u306a\u6280\u8853\u9078\u5b9a\u304c\u4e0d\u53ef\u6b20\u3067\u3059\u3002\u30b7\u30b9\u30c6\u30e0\u306e\u8981\u4ef6\u306b\u5fdc\u3058\u3066\u3001\u9069\u5207\u306a\u624b\u6cd5\u3092\u63a1\u7528\u3057\u307e\u3057\u3087\u3046\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c7\u30fc\u30bf\u4fdd\u8b77\u306f\u3001\u30d7\u30e9\u30a4\u30d0\u30b7\u30fc\u3084\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[500],"tags":[553,554],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3660"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=3660"}],"version-history":[{"count":1,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3660\/revisions"}],"predecessor-version":[{"id":3661,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3660\/revisions\/3661"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=3660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=3660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=3660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}