Main Content

setSecret

Add secret to MATLAB vault

Since R2024a

Description

example

setSecret(secretname) adds a secret with the specified name to your MATLAB® vault, which is accessible only from the exact combination of your operating system account and local machine.

Your vault and secrets, which do not leave your local machine, persist across MATLAB sessions. Each secret consists of a name, value, and optional metadata.

  • Secret name – A unique case-sensitive text identifier for the secret. The secret name is stored unencrypted in your vault as a string scalar.

  • Secret value – A text value associated with the secret. The Secret Prompt dialog box, where you enter the secret value, supports copy-paste functionality. The secret value is stored encrypted in your vault using industry standard AES-256 encryption. The secret value is returned as a string scalar.

  • Secret metadata – A dictionary containing additional information associated with the secret. The optional secret metadata is stored unencrypted in your vault.

example

setSecret(secretname,Overwrite=tf) specifies whether to overwrite an existing secret value in the vault.

Examples

collapse all

Create a secret by initiating the Secret Prompt dialog box with the name of your secret.

setSecret("SFTPpassword")

Use the dialog box to set your secret value and add the secret to your MATLAB vault. Toggle the eye icon in the text box to hide or show the characters in your value.

Secret Prompt dialog box, with a text box to enter the SFTPpassword value

View all the secret names and metadata sizes in your vault. listSecrets does not show secret values or the details of secret metadata.

listSecrets
      SecretName                      SecretMetadata                 
    ______________    _______________________________________________

    "SFTPpassword"    {[dictionary (string ⟼ cell) with no entries]}

Create a secret to store your SFTP server password by initiating the Secret Prompt dialog box with the name of your secret.

setSecret("SFTPpassword")

Use the dialog box to set your secret value and add the secret to your MATLAB vault. Toggle the eye icon in the text box to hide or show the characters in your value.

Secret Prompt dialog box, with a text box to enter the SFTPpassword value

To provide the SFTP server password, use the secret from your vault containing the password value.

s = sftp("sftp.example.net","adam",Password=getSecret("SFTPpassword"));

View all the secret names and metadata sizes in your vault.

listSecrets
      SecretName                      SecretMetadata                 
    ______________    _______________________________________________

    "SFTPpassword"    {[dictionary (string ⟼ cell) with no entries]}

Initiate the Secret Prompt dialog box with the name of the secret whose value you want to overwrite. You can use tab completion to select an existing secret.

setSecret("SFTPpassword",Overwrite=true)

Set your new secret value using the dialog box.

Secret Prompt dialog box, with a text box to enter the SFTPpassword value

View your updated vault. Note that there is no change to the secret name or metadata.

listSecrets
      SecretName                      SecretMetadata                 
    ______________    _______________________________________________

    "SFTPpassword"    {[dictionary (string ⟼ cell) with no entries]}

Input Arguments

collapse all

Unique case-sensitive text identifier for the secret, specified as a string scalar or character vector. You can use a secret to hold sensitive information, such as passwords, certificates, credentials, OAuth tokens, and other configuration data for:

  • SFTP and FTP servers

  • Password-protected files, such as PDFs

  • Password-protected archives, such as zip files

  • Cloud providers, such as Amazon S3™ and Windows Azure® Blob Storage

  • API keys, SSH keys, and encryption keys

  • Databases and applications

The forward slash character (/) is not supported in secretname.

Overwrite the value of an existing secret with the same name, specified as a numeric or logical 0 (false) or 1 (true). This argument does not affect the metadata of the existing secret. If Overwrite is false, setSecret produces an error if you attempt to overwrite the value of an existing secret. If Overwrite is true, setSecret overwrites the value of an existing secret.

Version History

Introduced in R2024a