setSecret - Add secret to MATLAB vault - MATLAB (original) (raw)

Add secret to MATLAB vault

Since R2024a

Syntax

Description

setSecret([secretname](#mw%5Feb557c9c-5cf9-4956-8e48-9d52c1633900)) 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.

For increased security when you use MATLAB Online™, enable two-step verification for your MathWorks® Account.

example

setSecret([secretname](#mw%5Feb557c9c-5cf9-4956-8e48-9d52c1633900),Overwrite=[tf](#mw%5Fecceac04-026e-4759-9c65-826f0d09d807)) specifies whether to overwrite an existing secret value in the vault.

example

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.

  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.

  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.

  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:

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

expand all

The secretname argument now supports the forward slash character (/).