title: AES encrypt/decrypt with Bouncy Castle provider
body: <p>Here is my implementation of a AES 256 encrypt and decrypt, developed with the native library of JDK 5: </p>
  
  <pre><code>public static String encrypt(String key, String toEncrypt) throws Exception {
      Key skeySpec = generateKeySpec(key);
      Cipher cipher = Cipher.getInstance("AES");
      cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
      byte[] encrypted = cipher.doFinal(toEncrypt.getBytes());
      byte[] encryptedValue = Base64.encodeBase64(encrypted);
      return new String(encryptedValue);
  }
  
  public static String decrypt(String key, String encrypted) throws Exception {
      Key skeySpec = generateKeySpec(key);
      Cipher cipher = Cipher.getInstance("AES");
      cipher.init(Cipher.DECRYPT_MODE, skeySpec);
      byte[] decodedBytes = Base64.decodeBase64(encrypted.getBytes());
      byte[] original = cipher.doFinal(decodedBytes);
      return new String(original);
  }
  </code></pre>
  
  <p>I want to implement the same methods with the Boucy Castle API (Java): I've searched a lot, tested a lot, without results ... can someone help me?</p>
  
  <p>Thanks</p>