Skip to content

Commit

Permalink
Fix decryption
Browse files Browse the repository at this point in the history
Rubenicos committed Nov 10, 2024
1 parent b5619d1 commit d3ab901
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/com/saicone/delivery4j/util/Encryptor.java
Original file line number Diff line number Diff line change
@@ -31,17 +31,19 @@ static Encryptor of(@NotNull String transformation, @NotNull SecretKey key) thro

@NotNull
static Encryptor of(@NotNull String transformation, @NotNull SecretKey key, @NotNull Charset charset) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
final Cipher cipher = Cipher.getInstance(transformation);
cipher.init(Cipher.ENCRYPT_MODE, key);
final Cipher encrypt = Cipher.getInstance(transformation);
encrypt.init(Cipher.ENCRYPT_MODE, key);
final Cipher decrypt = Cipher.getInstance(transformation);
decrypt.init(Cipher.DECRYPT_MODE, key);
return new Encryptor() {
@Override
public byte[] encrypt(@NotNull String input) throws IllegalBlockSizeException, BadPaddingException {
return cipher.doFinal(input.getBytes(charset));
return encrypt.doFinal(input.getBytes(charset));
}

@Override
public @NotNull String decrypt(byte[] input) throws IllegalBlockSizeException, BadPaddingException {
return new String(cipher.doFinal(input), charset);
return new String(decrypt.doFinal(input), charset);
}
};
}

0 comments on commit d3ab901

Please sign in to comment.