mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-05-24 16:26:21 -04:00
Check for secret key existence
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user