Check for secret key existence

This commit is contained in:
crschnick
2025-01-16 07:22:37 +00:00
parent 1bb87fa35b
commit f92c5c4b9b
2 changed files with 5 additions and 1 deletions

View File

@@ -27,7 +27,7 @@ public class VaultKeySecretValue extends AesSecretValue {
@Override
protected SecretKey getSecretKey() {
return DataStorage.get().getVaultKey();
return DataStorage.get() != null ? DataStorage.get().getVaultKey() : null;
}
@Override

View File

@@ -48,6 +48,10 @@ public abstract class AesSecretValue extends EncryptedSecretValue {
@SneakyThrows
public byte[] encrypt(byte[] c) {
SecretKey secretKey = getSecretKey();
if (secretKey == null) {
throw new IllegalStateException("Missing secret key");
}
Cipher cipher = Cipher.getInstance(ENCRYPT_ALGO);
var iv = getNonce(IV_LENGTH_BYTE);
cipher.init(Cipher.ENCRYPT_MODE, secretKey, new GCMParameterSpec(TAG_LENGTH_BIT, iv));