- ecipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
- dcipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
- ecipher.init(Cipher.ENCRYPT_MODE, key);
- dcipher.init(Cipher.DECRYPT_MODE, key);
- } catch (NoSuchAlgorithmException e) {
- // Every implementation of the Java platform is required to support
- // this standard Cipher transformation with 128 bits keys
- e.printStackTrace();
- } catch (NoSuchPaddingException e) {
- // Every implementation of the Java platform is required to support
- // this standard Cipher transformation with 128 bits keys
- e.printStackTrace();
- } catch (InvalidKeyException e) {
- // Every implementation of the Java platform is required to support
- // this standard Cipher transformation with 128 bits keys
+ // bytes32 = 32 bytes, 32 > 16
+ byte[] iv = new byte[16];
+ for (int i = 0; i < iv.length; i++) {
+ iv[i] = bytes32[i];
+ }
+ IvParameterSpec ivspec = new IvParameterSpec(iv);
+ Cipher cipher = Cipher.getInstance(AES_NAME);
+ cipher.init(mode, new SecretKeySpec(bytes32, "AES"), ivspec);
+ return cipher;
+ } catch (Exception e) {