---
title: Secret
summary: A secret from a secret store.
url: https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/secret_store/class.Secret/
---

**Kind:** Class  
**Module:** [secret_store](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/secret_store/)  
**Package:** compute-sdk-cpp 0.7.0  
**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/secret_store.h#L21

Include `fastly/secret_store.h` to use this class.

A secret from a secret store.

A secret name has a maximum length of 255 bytes and must contain only letters, numbers, dashes (-), underscores (_), and periods (.).

A secret value has a maximum length of 64 KiB.

## Methods

### from_bytes

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/secret_store.h#L38

```cpp
fastly::expected<Secret> fastly::secret_store::Secret::from_bytes(std::vector<uint8_t> data)
```

Create a new "Secret" from the given memory. This is *not* the suggested way to create [`Secret`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/secret_store/class.Secret/)s; instead, we suggest using [`SecretStore::get`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/secret_store/class.SecretStore/#method-get). This secret will *NOT* be shared with other sessions.

This method can be used for data that should be secret, but is being obtained by some other means than the secret store. New "ecrets" created this way use plaintext/ only, and live in the session's memory unencrypted for much longer than secrets generated by [`SecretStore::get`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/secret_store/class.SecretStore/#method-get). They should thus only be used in situations in which an API requires a [`Secret`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/secret_store/class.Secret/), but you cannot (for whatever reason) use a [`SecretStore`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/secret_store/class.SecretStore/) to store them. As the early note says, this [`Secret`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/secret_store/class.Secret/) will be local to the current session, and will not be shared with other sessions of this service.

**Parameters**

- `data`: `std::vector<uint8_t>`

**Returns**

`fastly::expected<Secret>`

### plaintext

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/secret_store.h#L57

```cpp
std::string fastly::secret_store::Secret::plaintext()
```

Read the plaintext contents of a secret into memory as a byte buffer.

Once a secret is read into memory, a secret's contents can be repeatedly accessed cheaply.

###### Examples

Check if [`fastly::http::HeaderValue`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/http/class.HeaderValue/) matches the contents of a secret.

**Returns**

`std::string`

```cpp
auto secret{secret_store.get("example").value()};
auto header{request.get_header("example").value()};
if (secret.plaintext() == header) {
    std::cout << "you have guessed correctly!";
}
```
