Vault | C# SDK
Vault
VaultClientVault client.
var config = new Config("pangea_token", "pangea_domain");
var builder = new VaultClient.Builder(config);
var client = builder.Build();
Change state
VaultClient.StateChange(string, int, ItemVersionState)Change the state of a specific version of a secret or key.
var response = await client.StateChange(
"pvi_p6g5i3gtbvqvc3u6zugab6qs6r63tqf5",
1,
ItemVersionState.Deactivated
);
Delete
VaultClient.Delete(string)Delete a secret, key or folder.
await client.Delete("pvi_p6g5i3gtbvqvc3u6zugab6qs6r63tqf5");
Retrieve
VaultClient.Get(GetRequest)Retrieve a secret, key or folder, and any associated information.
var request = new GetRequest
("pvi_p6g5i3gtbvqvc3u6zugab6qs6r63tqf5")
;
var response = await client.Get(request);
Get Bulk
VaultClient.GetBulk(GetBulkRequest)Retrieve a list of secrets, keys and folders.
var response = await client.GetBulk(new()
{
Filter = new Dictionary<string, string>()
{
{ "id", "pvi_123" }
}
});
List
VaultClient.List(ListRequest)Retrieve a list of secrets, keys and folders, and their associated information.
var request = new ListRequest();
var response = await client.List(request);
Update
VaultClient.Update(UpdateRequest)Update information associated with a secret, key or folder.
var request = new UpdateRequest
("pvi_p6g5i3gtbvqvc3u6zugab6qs6r63tqf5")
.WithFolder("/personal")
;
var response = await client.Update(request);
Secret store
VaultClient.SecretStore(SecretStoreRequest)Store a secret in the vault service.
var request = new SecretStoreRequest
("12sdfgs4543qv@#%$casd", "my-very-secret-secret")
;
var response = await client.SecretStore(request);
Secret rotate
VaultClient.SecretRotate(SecretRotateRequest)Rotate a secret in the vault service.
var request = new SecretRotateRequest(
"pvi_p6g5i3gtbvqvc3u6zugab6qs6r63tqf5",
"12sdfgs4543qv@#%$casd")
.WithRotationState(ItemVersionState.Deactivated)
;
var response = await client.SecretRotate(request);
Symmetric generate
VaultClient.SymmetricGenerate(SymmetricGenerateRequest)Generate a symmetric key.
SymmetricGenerateRequest request = new SymmetricGenerateRequest
(
SymmetricAlgorithm.AES128_CFB,
KeyPurpose.Encryption,
"my-very-secret-secret")
;
var response = await client.SymmetricGenerate(request);
Asymmetric generate
VaultClient.AsymmetricGenerate(AsymmetricGenerateRequest)Generate an asymmetric key.
AsymmetricGenerateRequest request = new AsymmetricGenerateRequest
(
AsymmetricAlgorithm.ED25519,
KeyPurpose.Signing,
"my-very-secret-secret")
;
var response = await client.AsymmetricGenerate(request);
Asymmetric store
VaultClient.AsymmetricStore(AsymmetricStoreRequest)Import an asymmetric key.
AsymmetricStoreRequest request = new AsymmetricStoreRequest
(
"encoded private key",
"-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEA8s5JopbEPGBylPBcMK+L5PqHMqPJW/5KYPgBHzZGncc=\n-----END PUBLIC KEY-----",
AsymmetricAlgorithm.RSA4096_OAEP_SHA256,
KeyPurpose.Signing,
"my-very-secret-secret")
;
var response = await client.AsymmetricStore(request);
Symmetric store
VaultClient.SymmetricStore(SymmetricStoreRequest)Import a symmetric key.
SymmetricStoreRequest request = new SymmetricStoreRequest
(
"lJkk0gCLux+Q+rPNqLPEYw==",
SymmetricAlgorithm.AES128_CFB,
KeyPurpose.Encryption,
"my-very-secret-secret")
;
var response = await client.SymmetricStore(request);
Rotate
VaultClient.KeyRotate(KeyRotateRequest)Manually rotate a symmetric or asymmetric key.
KeyRotateRequest request = new KeyRotateRequest
(
"pvi_p6g5i3gtbvqvc3u6zugab6qs6r63tqf5",
ItemVersionState.Deactivated)
.WithEncodedSymmetricKey("lJkk0gCLux+Q+rPNqLPEYw==")
;
var response = await client.KeyRotate(request);
Encrypt
VaultClient.Encrypt(EncryptRequest)Encrypt a message using a key.
EncryptRequest request = new EncryptRequest
(
"pvi_p6g5i3gtbvqvc3u6zugab6qs6r63tqf5",
"lJkk0gCLux+Q+rPNqLPEYw==")
.WithVersion(2)
;
var response = await client.Encrypt(request);
Decrypt
VaultClient.Decrypt(DecryptRequest)Decrypt a message using a key.
DecryptRequest request = new DecryptRequest
(
"pvi_p6g5i3gtbvqvc3u6zugab6qs6r63tqf5",
"lJkk0gCLux+Q+rPNqLPEYw==")
.WithVersion(2)
;
var response = await client.Decrypt(request);
Sign
VaultClient.Sign(SignRequest)Sign a message using a key.
SignRequest request = new SignRequest
(
"pvi_p6g5i3gtbvqvc3u6zugab6qs6r63tqf5",
"lJkk0gCLux+Q+rPNqLPEYw==")
;
var response = await client.Sign(request);
JWT Sign
VaultClient.JWTSign(string, string)Sign a JSON Web Token (JWT) using a key.
string payload = "{\"sub\": \"1234567890\",\"name\": \"John Doe\",\"admin\": true}";
var response = await client
.JWTSign("pvi_p6g5i3gtbvqvc3u6zugab6qs6r63tqf5", payload);
Verify
VaultClient.Verify(VerifyRequest)Verify a signature using a key.
var request = new VerifyRequest
(
"pvi_p6g5i3gtbvqvc3u6zugab6qs6r63tqf5",
"data2verify",
"signature")
;
var response = await client.Verify(request);
JWT Verify
VaultClient.JWTVerify(JWTVerifyRequest)Verify the signature of a JSON Web Token (JWT).
var request = new JWTVerifyRequest
("ewogICJhbGciO...")
;
var verifyResponse = await client.JWTVerify(request);
JWT Retrieve
VaultClient.JWKGet(JWKGetRequest)Retrieve a key in JWK format.
var request = new JWKGetRequest
("jwkid")
.WithVersion("2")
;
var response = await client.JWKGet(request)
Create
VaultClient.FolderCreate(FolderCreateRequest)Creates a folder.
var request = new FolderCreateRequest
(
"folder_name",
"parent/folder/name")
;
var response = await client.FolderCreate(request);
Encrypt structured
VaultClient.EncryptStructured<T>(EncryptStructuredRequest<T>, CancellationToken)Encrypt parts of a JSON object.
var data = new SomeModel { Name = "...", Occupation = "..." };
var request = new EncryptStructuredRequest<SomeModel>(encryptionKeyId, data, "$.name");
var response = await client.EncryptStructured(request);
Decrypt structured
VaultClient.DecryptStructured<T>(EncryptStructuredRequest<T>, CancellationToken)Decrypt parts of a JSON object.
var data = new SomeModel { Name = "...", Occupation = "..." };
var request = new EncryptStructuredRequest<SomeModel>(encryptionKeyId, data, "$.name");
var response = await client.DecryptStructured(request);
Encrypt transform
VaultClient.EncryptTransform(EncryptTransformRequest, CancellationToken)Encrypt using a format-preserving algorithm (FPE).
var request = new EncryptTransformRequest
{
ID = "pvi_[...]",
PlainText = "123-4567-8901",
Tweak = "MTIzMTIzMT==",
Alphabet = TransformAlphabet.ALPHANUMERIC
};
var encrypted = await client.EncryptTransform(request);
Decrypt transform
VaultClient.DecryptTransform(DecryptTransformRequest, CancellationToken)Decrypt using a format-preserving algorithm (FPE).
var request = new DecryptTransformRequest
{
ID = "pvi_[...]",
CipherText = "123-4567-8901",
Tweak = "MTIzMTIzMT==",
Alphabet = TransformAlphabet.ALPHANUMERIC
};
var decrypted = await client.DecryptTransform(decryptRequest);
Export
VaultClient.Export(ExportRequest, CancellationToken)Export a symmetric or asymmetric key.
// Generate an exportable key.
var generateRequest = new AsymmetricGenerateRequest(
AsymmetricAlgorithm.RSA4096_PSS_SHA512,
KeyPurpose.Encryption,
"a-name-for-the-key"
).WithExportable(true);
var generated = await client.AsymmetricGenerate(generateRequest);
var key = generated.Result.ID;
// Then it can be exported whenever needed.
var exported = await client.Export(new ExportRequest(id: key));