Skip to content

Commit

Permalink
rm bc encryption provider
Browse files Browse the repository at this point in the history
  • Loading branch information
jeqo committed Jun 7, 2023
1 parent 2cd258d commit ce47baa
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,20 @@

import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.security.Security;
import java.util.Random;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

public class AesKeyAware {
protected static int ivSize;
protected static SecretKeySpec secretKey;
protected static byte[] aad;

static {
Security.addProvider(new BouncyCastleProvider());
}

static void initCrypto() {
// These are tests, we don't need a secure source of randomness.
final Random random = new Random();
Expand Down Expand Up @@ -69,7 +61,7 @@ protected static Cipher decryptionCipherSupplier(final byte[] encryptedChunk) {
try {
final Cipher encryptCipher = getCipher();
encryptCipher.init(Cipher.DECRYPT_MODE, secretKey,
new IvParameterSpec(encryptedChunk, 0, ivSize),
new GCMParameterSpec(128, encryptedChunk, 0, ivSize),
SecureRandom.getInstanceStrong());
encryptCipher.updateAAD(aad);
return encryptCipher;
Expand All @@ -80,8 +72,8 @@ protected static Cipher decryptionCipherSupplier(final byte[] encryptedChunk) {

protected static Cipher getCipher() {
try {
return Cipher.getInstance("AES/GCM/NoPadding", "BC");
} catch (final NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException e) {
return Cipher.getInstance("AES/GCM/NoPadding");
} catch (final NoSuchAlgorithmException | NoSuchPaddingException e) {
throw new RuntimeException(e);
}
}
Expand Down

0 comments on commit ce47baa

Please sign in to comment.