Code example for SecretKeySpec

0
  private Cipher getCipher(byte[] messageBytes)
      throws InvalidEncryptedSignalException, InvalidKeyException, 
             InvalidAlgorithmParameterException, NoSuchAlgorithmException, 
             NoSuchPaddingException, IOException 
  { 
    SecretKeySpec cipherKey = new SecretKeySpec(getCipherKey(), "AES");
    byte[] ivBytes          = new byte[16];
 
    if (messageBytes.length < ivBytes.length)
      throw new InvalidEncryptedSignalException("Message shorter than IV length."); 
 
    System.arraycopy(messageBytes, IV_OFFSET, ivBytes, 0, ivBytes.length);
 
    Cipher cipher      = Cipher.getInstance("AES/CBC/PKCS5Padding");
    IvParameterSpec iv = new IvParameterSpec(ivBytes);
    cipher.init(Cipher.DECRYPT_MODE, cipherKey, iv);
 
    return cipher;
  } 
 
Contextual code suggestions in your IDE  Get Codota for Java