Main Content

secretID

Secret object

Since R2025a

Description

Use a secretID object to represent the name of a secret. A secretID object allows you to refer to encrypted secrets in your MATLAB® vault without exposing their actual values. You can keep credentials and other sensitive information encrypted when setting properties of weboptions and Credentials objects by using secretID objects.

Creation

Description

secret = secretID(secretname) creates a secretID object that you can use to refer to the specified existing secret in your MATLAB vault.

example

Input Arguments

expand all

Secret identifier, specified as a string scalar or character vector. secretname cannot be empty.

This argument sets the Name property.

Properties

expand all

Secret identifier, specified as a string scalar or character vector. Name cannot be empty.

Example: "Httpbin.Username"

Examples

collapse all

Create secrets for a username and password by calling the setSecret function with a name for each secret. Use the Secret Prompt dialog box that opens to set your secret values and add the secrets to your MATLAB vault.

setSecret("usernameName")
setSecret("passwordName")

Create secretID objects by referencing each of your secrets by their names. Then use the secretID objects to provide your username and password to a weboptions object.

u = secretID("usernameName");
p = secretID("passwordName");
options = weboptions(Username=u,Password=p);

Save your variables to a MAT file. Because you specified secretID objects, the MAT file saves your data without saving plain text values of your username and password.

save("myvars.mat")

More About

expand all

Version History

Introduced in R2025a