2

I keep on getting java.security.NoSuchAlgorithmException: no such algorithm: AES for provider BC with my code below. It looks like I have included all the things I need.

My class is as follows:

....
import org.bouncycastle.jce.provider.BouncyCastleProvider;

class ... {


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

public CryptSession(String _algo, String _provider, String _keyAlgo, int _keySize)
    throws
        NoSuchAlgorithmException,
        NoSuchProviderException
{
    KeyGenerator generator = KeyGenerator.getInstance("AES", "BC"); // KeyGenerator.getInstance(_algo, _provider);
    generator.init(256); //generator.init(_keySize);

    this._algo = _algo;
    this._provider = _provider;

    this._keyAlgo = _keyAlgo;
    this._keySize = _keySize;

    this._key = generator.generateKey();
}
...
gianebao
  • 17,718
  • 3
  • 31
  • 40
  • This (similar) code works with Java 7 and BC 1.50. You should check if the minimally possible code works (simple class with main method that registers provider and gets the key generator), and you should provide additional details on software versions used and the environment where your code runs. – Oleg Estekhin May 06 '14 at 10:19
  • And you should examine the stacktrace (or add it to the question). It is quite possible that the exception happens somewhere else and not in the mangled code that you posted. – Oleg Estekhin May 06 '14 at 10:21

1 Answers1

1

You need to edit java security policy file add bauntycasle provider to policy file located in jdk/bin/lib directory

Shakeeb Manjeri
  • 120
  • 1
  • 1
  • 9