Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Puoi utilizzare una chiave precondivisa (PSK) (chiamata anche segreto condiviso) per autenticare il tunnel VPN Cloud al tuo gateway VPN peer. Come best practice per la sicurezza, ti consigliamo di generare una chiave pre-condivisa sicura di 32 caratteri.
Utilizza i seguenti metodi per generare una chiave precondivisa sicura di 32 caratteri.
Per le definizioni dei termini utilizzati in questa pagina, consulta
Termini chiave.
Generare un PSK utilizzando JavaScript
Puoi generare la chiave precondivisa direttamente in un documento utilizzando JavaScript con l'API W3C Web Cryptography.
Questa API utilizza il
metodo Crypto.getRandomValues(),
che fornisce un metodo crittografico per generare una chiave precondivisa.
Il seguente codice genera una stringa casuale di 32 caratteri creando un array di 24 byte casuali e poi codificandoli in base64:
var a = new Uint8Array(24);
window.crypto.getRandomValues(a);
console.log(btoa(String.fromCharCode.apply(null, a)));
Per generare subito un PSK, fai clic su Rigenera:
Generare una PSK utilizzando OpenSSL
Nell'interfaccia a riga di comando Linux o macOS, esegui il seguente
comando OpenSSL:
openssl rand -base64 32
Genera un PSK utilizzando /dev/urandom
Su un sistema operativo Linux o macOS, utilizza /dev/urandom come fonte pseudocasuale per generare una chiave precondivisa.
Nell'interfaccia a riga di comando di Linux o macOS, esegui il seguente comando per
inviare l'input casuale a base64:
head -c 32 /dev/urandom | base64
Passa l'input casuale a una funzione di hashing, ad esempio sha256:
Su Linux:
head -c 4096 /dev/urandom | sha256sum | cut -b1-32
Su macOS:
head -c 4096 /dev/urandom | openssl sha256 | cut -b1-32
Passaggi successivi
Per utilizzare scenari di alta disponibilità e ad alto throughput o scenari con più sottoreti, consulta Configurazioni avanzate.
Per aiutarti a risolvere i problemi comuni che potresti riscontrare durante l'utilizzo di Cloud VPN, consulta la sezione Risoluzione dei problemi.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)."]]