Package codes.grow.packages.vault
Class Transit
java.lang.Object
codes.grow.packages.vault.Transit
Transit engine on one mount:
client.transit() (mount transit). Plaintexts are
bytes (text is UTF-8 encoded); ciphertexts, signatures and HMACs are vault:v<n>:...
strings.
Transit transit = client.transit();
Ciphertext ct = transit.encrypt("app-key", "hello");
byte[] plain = transit.decrypt("app-key", ct.ciphertext());
-
Method Summary
Modifier and TypeMethodDescriptionCreates anaes256-gcm96key (idempotent: an existing key is returned unchanged).createKey(String name, CreateKeyOptions options) Creates a key with options.Creates a key of a type.createKeyAsync(String name, CreateKeyOptions o) AsynchronouscreateKey(String, CreateKeyOptions).byte[]Decrypts a ciphertext.byte[]decrypt(String name, String ciphertext, TransitOptions options) Decrypts a ciphertext with options.CompletableFuture<byte[]> decryptAsync(String name, String ciphertext, TransitOptions o) Asynchronousdecrypt(String, String, TransitOptions).decryptBatch(String name, List<DecryptBatchItem> items) Decrypts many items in one request; seeencryptBatch(java.lang.String, java.util.List<codes.grow.packages.vault.EncryptBatchItem>)for error handling.decryptBatchAsync(String name, List<DecryptBatchItem> items) AsynchronousdecryptBatch(String, List).voidDeletes a key (needsdeletionAllowed, elseValidationException).deleteKeyAsync(String name) AsynchronousdeleteKey(String).encrypt(String name, byte[] plaintext, TransitOptions options) Encrypts bytes.Encrypts UTF-8 text.encryptAsync(String name, byte[] plaintext, TransitOptions o) Asynchronousencrypt(String, byte[], TransitOptions).encryptBatch(String name, List<EncryptBatchItem> items) Encrypts many items in one request.encryptBatchAsync(String name, List<EncryptBatchItem> items) AsynchronousencryptBatch(String, List).generateDataKey(String name) Generates a 256-bit data key encrypted with the transit key, plus its plaintext.generateDataKey(String name, boolean plaintext, int bits) Generates a data key.generateDataKeyAsync(String name, boolean plaintext, int bits, TransitOptions o) AsynchronousgenerateDataKey(String, boolean, int)(options: context).hash(byte[] input) SHA2-256 hash of the input, hex encoded.Hash of the input.Asynchronoushash(byte[], String, String).HMAC of the input with the key (vault:v<n>:<base64>).hmac(String name, byte[] input, TransitOptions options) HMAC with options (hash algorithm, key version).hmacAsync(String name, byte[] input, TransitOptions o) Asynchronoushmac(String, byte[], TransitOptions).listKeys()Key names (sorted); empty when there is none.AsynchronouslistKeys().mount()Returns the mount.randomBytes(int bytes) Random bytes from the server, base64 encoded.randomBytes(int bytes, String format) Random bytes from the server.randomBytesAsync(int bytes, String format) AsynchronousrandomBytes(int, String).Reads a key;NotFoundExceptionwhen missing.readKeyAsync(String name) AsynchronousreadKey(String).Re-encrypts a ciphertext with the latest key version without revealing the plaintext.rewrap(String name, String ciphertext, TransitOptions options) Re-encrypts with options (key version, context).rewrapAsync(String name, String ciphertext, TransitOptions o) Asynchronousrewrap(String, String, TransitOptions).Adds a new key version.rotateKeyAsync(String name) AsynchronousrotateKey(String).Signs the input with an asymmetric key.sign(String name, byte[] input, TransitOptions options) Signs with options (hash algorithm, signature algorithm, prehashed, key version, context).signAsync(String name, byte[] input, TransitOptions o) Asynchronoussign(String, byte[], TransitOptions).toString()updateKeyConfig(String name, KeyConfig config) Updates key settings.updateKeyConfigAsync(String name, KeyConfig c) AsynchronousupdateKeyConfig(String, KeyConfig).booleanVerifies a signature;falsefor an invalid signature (not an error).booleanverify(String name, byte[] input, String signature, TransitOptions options) Verifies a signature with options.verifyAsync(String name, byte[] input, String signature, String hmac, TransitOptions o) Asynchronous verification of a signature or an HMAC (exactly one must be given).booleanverifyHmac(String name, byte[] input, String hmac) Verifies an HMAC produced byhmac(java.lang.String, byte[]).
-
Method Details
-
mount
Returns the mount.- Returns:
- the mount path
-
createKey
Creates anaes256-gcm96key (idempotent: an existing key is returned unchanged).- Parameters:
name- key name- Returns:
- the key
-
createKey
Creates a key of a type.- Parameters:
name- key nametype- key type, e.g.ed25519- Returns:
- the key
-
createKey
Creates a key with options.- Parameters:
name- key nameoptions- key options- Returns:
- the key
-
createKeyAsync
AsynchronouscreateKey(String, CreateKeyOptions).- Parameters:
name- key nameo- key options- Returns:
- a future with the key
-
readKey
Reads a key;NotFoundExceptionwhen missing.- Parameters:
name- key name- Returns:
- the key
-
readKeyAsync
AsynchronousreadKey(String).- Parameters:
name- key name- Returns:
- a future with the key
-
listKeys
Key names (sorted); empty when there is none.- Returns:
- the names
-
listKeysAsync
AsynchronouslistKeys().- Returns:
- a future with the names
-
rotateKey
Adds a new key version.- Parameters:
name- key name- Returns:
- the updated key
-
rotateKeyAsync
AsynchronousrotateKey(String).- Parameters:
name- key name- Returns:
- a future with the updated key
-
updateKeyConfig
Updates key settings.- Parameters:
name- key nameconfig- settings- Returns:
- the updated key
-
updateKeyConfigAsync
AsynchronousupdateKeyConfig(String, KeyConfig).- Parameters:
name- key namec- settings- Returns:
- a future with the updated key
-
deleteKey
Deletes a key (needsdeletionAllowed, elseValidationException).- Parameters:
name- key name
-
deleteKeyAsync
AsynchronousdeleteKey(String).- Parameters:
name- key name- Returns:
- a future completed when done
-
encrypt
Encrypts UTF-8 text.- Parameters:
name- key nameplaintext- text- Returns:
- the ciphertext
-
encrypt
Encrypts bytes.- Parameters:
name- key nameplaintext- bytesoptions- context, key version, associated data- Returns:
- the ciphertext
-
encryptAsync
Asynchronousencrypt(String, byte[], TransitOptions).- Parameters:
name- key nameplaintext- byteso- options- Returns:
- a future with the ciphertext
-
decrypt
Decrypts a ciphertext.- Parameters:
name- key nameciphertext-vault:v<n>:ciphertext- Returns:
- the plaintext bytes
-
decrypt
Decrypts a ciphertext with options.- Parameters:
name- key nameciphertext- ciphertextoptions- context, associated data- Returns:
- the plaintext bytes
-
decryptAsync
Asynchronousdecrypt(String, String, TransitOptions).- Parameters:
name- key nameciphertext- ciphertexto- options- Returns:
- a future with the plaintext bytes
-
rewrap
Re-encrypts a ciphertext with the latest key version without revealing the plaintext.- Parameters:
name- key nameciphertext- ciphertext- Returns:
- the new ciphertext
-
rewrap
Re-encrypts with options (key version, context).- Parameters:
name- key nameciphertext- ciphertextoptions- options- Returns:
- the new ciphertext
-
rewrapAsync
Asynchronousrewrap(String, String, TransitOptions).- Parameters:
name- key nameciphertext- ciphertexto- options- Returns:
- a future with the new ciphertext
-
encryptBatch
Encrypts many items in one request. Results are in input order; a failed item haserrorset (the call itself fails only when the whole request fails).- Parameters:
name- key nameitems- items- Returns:
- the results
-
encryptBatchAsync
public CompletableFuture<List<EncryptBatchResult>> encryptBatchAsync(String name, List<EncryptBatchItem> items) AsynchronousencryptBatch(String, List).- Parameters:
name- key nameitems- items- Returns:
- a future with the results
-
decryptBatch
Decrypts many items in one request; seeencryptBatch(java.lang.String, java.util.List<codes.grow.packages.vault.EncryptBatchItem>)for error handling.- Parameters:
name- key nameitems- items- Returns:
- the results
-
decryptBatchAsync
public CompletableFuture<List<DecryptBatchResult>> decryptBatchAsync(String name, List<DecryptBatchItem> items) AsynchronousdecryptBatch(String, List).- Parameters:
name- key nameitems- items- Returns:
- a future with the results
-
generateDataKey
Generates a 256-bit data key encrypted with the transit key, plus its plaintext.- Parameters:
name- key name- Returns:
- the data key
-
generateDataKey
Generates a data key.- Parameters:
name- key nameplaintext- also return the plaintext (plaintextvariant) instead of only the ciphertext (wrappedvariant)bits- 128, 256 or 512- Returns:
- the data key
-
generateDataKeyAsync
public CompletableFuture<DataKey> generateDataKeyAsync(String name, boolean plaintext, int bits, TransitOptions o) AsynchronousgenerateDataKey(String, boolean, int)(options: context).- Parameters:
name- key nameplaintext- also return the plaintextbits- key sizeo- options- Returns:
- a future with the data key
-
hmac
HMAC of the input with the key (vault:v<n>:<base64>).- Parameters:
name- key nameinput- bytes- Returns:
- the HMAC
-
hmac
HMAC with options (hash algorithm, key version).- Parameters:
name- key nameinput- bytesoptions- options- Returns:
- the HMAC
-
hmacAsync
Asynchronoushmac(String, byte[], TransitOptions).- Parameters:
name- key nameinput- byteso- options- Returns:
- a future with the HMAC
-
sign
Signs the input with an asymmetric key.- Parameters:
name- key nameinput- bytes- Returns:
- the signature
-
sign
Signs with options (hash algorithm, signature algorithm, prehashed, key version, context).- Parameters:
name- key nameinput- bytesoptions- options- Returns:
- the signature
-
signAsync
Asynchronoussign(String, byte[], TransitOptions).- Parameters:
name- key nameinput- byteso- options- Returns:
- a future with the signature
-
verify
Verifies a signature;falsefor an invalid signature (not an error).- Parameters:
name- key nameinput- signed bytessignature-vault:v<n>:signature- Returns:
- whether the signature is valid
-
verify
Verifies a signature with options.- Parameters:
name- key nameinput- signed bytessignature- signatureoptions- options- Returns:
- whether the signature is valid
-
verifyHmac
Verifies an HMAC produced byhmac(java.lang.String, byte[]).- Parameters:
name- key nameinput- byteshmac-vault:v<n>:HMAC- Returns:
- whether the HMAC is valid
-
verifyAsync
public CompletableFuture<Boolean> verifyAsync(String name, byte[] input, String signature, String hmac, TransitOptions o) Asynchronous verification of a signature or an HMAC (exactly one must be given).- Parameters:
name- key nameinput- bytessignature- signature, or nullhmac- HMAC, or nullo- options- Returns:
- a future with the result
-
hash
SHA2-256 hash of the input, hex encoded.- Parameters:
input- bytes- Returns:
- the hash
-
hash
Hash of the input.- Parameters:
input- bytesalgorithm- e.g.sha2-256(default),sha2-512,sha3-256; may be nullformat-hex(default) orbase64; may be null- Returns:
- the hash
-
hashAsync
Asynchronoushash(byte[], String, String).- Parameters:
input- bytesalgorithm- algorithm, may be nullformat- format, may be null- Returns:
- a future with the hash
-
randomBytes
Random bytes from the server, base64 encoded.- Parameters:
bytes- number of bytes- Returns:
- the base64 text
-
randomBytes
Random bytes from the server.- Parameters:
bytes- number of bytes (positive)format-base64orhex- Returns:
- the encoded bytes
-
randomBytesAsync
AsynchronousrandomBytes(int, String).- Parameters:
bytes- number of bytesformat- format, may be null for base64- Returns:
- a future with the encoded bytes
-
toString
-