diff --git a/src/main/java/swiss/qpq/gajumaru/core/crypto/Vault.java b/src/main/java/swiss/qpq/gajumaru/core/crypto/Vault.java index 08ae5c3..c1470da 100644 --- a/src/main/java/swiss/qpq/gajumaru/core/crypto/Vault.java +++ b/src/main/java/swiss/qpq/gajumaru/core/crypto/Vault.java @@ -62,16 +62,10 @@ public final class Vault { byte[] iv = new byte[IV_LENGTH]; new SecureRandom().nextBytes(iv); - Cipher cipher = Cipher.getInstance(AES_GCM); - GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH, iv); - cipher.init(Cipher.ENCRYPT_MODE, key, spec); - - byte[] ciphertext = cipher.doFinal(plaintext); + byte[] ciphertext = encrypt(key, iv, plaintext); return new Ciphertext(iv, ciphertext); } catch (Exception e) { - String msg = e.getMessage(); - if (msg == null) msg = e.toString(); - throw new Exception("Vault.encrypt failed: " + msg, e); + throw new Exception("Vault.encrypt failed: " + e.getMessage(), e); } } @@ -101,7 +95,7 @@ public final class Vault { } catch (Exception e) { String msg = e.getMessage(); if (msg == null) msg = e.toString(); - throw new Exception("Vault.decrypt failed: " + msg, e); + throw new Exception("Vault.decrypt failed [" + e.getClass().getSimpleName() + "]: " + msg, e); } } }