[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-05 UTC。"],[],[],null,["# Generate a strong pre-shared key\n\nYou can use a *pre-shared key (PSK)* (also called a *shared secret*) to\nauthenticate the Cloud VPN tunnel to your peer VPN gateway. As a security\nbest practice, we recommend that you generate a strong 32-character\npre-shared key.\n\nUse the following methods to generate a strong 32-character pre-shared key.\n\nFor more information about Cloud VPN, see the\n[Cloud VPN overview](/network-connectivity/docs/vpn/concepts/overview).\n\nFor definitions of terms used on this page, see\n[Key terms](/network-connectivity/docs/vpn/concepts/key-terms).\n\nGenerate a PSK by using JavaScript\n----------------------------------\n\nYou can generate the pre-shared key directly in a document by using JavaScript\nwith the\n[W3C Web Cryptography API](https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues).\nThis API uses the\n[Crypto.getRandomValues() method](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues),\nwhich provides a cryptographic way of generating a pre-shared key.\n\nThe following code generates a random 32-character string by creating an\narray of 24 random bytes and then base64 encoding those bytes: \n\n```\n var a = new Uint8Array(24);\n window.crypto.getRandomValues(a);\n\n console.log(btoa(String.fromCharCode.apply(null, a)));\n```\n\nTo generate a PSK now, click **Regenerate**:\n\n```\n\n```\nRegenerate\n\nGenerate a PSK by using OpenSSL\n-------------------------------\n\nIn the Linux or macOS command-line interface, run the following\n[OpenSSL](https://www.openssl.org/) command: \n\n```\nopenssl rand -base64 32\n```\n\nGenerate a PSK by using `/dev/urandom`\n--------------------------------------\n\nOn a Linux or macOS operating system, use `/dev/urandom` as a\npseudorandom source to generate a pre-shared key.\n\n1. In the Linux or macOS command-line interface, run the following command to\n send the random input to `base64`:\n\n ```\n head -c 32 /dev/urandom | base64\n ```\n2. Pass the random input through a hashing function, such as `sha256`:\n\n - On Linux:\n\n ```\n head -c 4096 /dev/urandom | sha256sum | cut -b1-32\n ```\n - On macOS:\n\n ```\n head -c 4096 /dev/urandom | openssl sha256 | cut -b1-32\n ```\n\nWhat's next\n-----------\n\n- To use high-availability and high-throughput scenarios or multiple subnet scenarios, see [Advanced configurations](/network-connectivity/docs/vpn/concepts/advanced).\n- To help you solve common issues that you might encounter when using Cloud VPN, see [Troubleshooting](/network-connectivity/docs/vpn/support/troubleshooting)."]]