Java tutorial
//package com.java2s; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import javax.crypto.Cipher; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; public class Main { public static Cipher createCipher(String algorithmProviderPadding, SecretKey sk, int mode) { try { Cipher ch = Cipher.getInstance(algorithmProviderPadding); ch.init(mode, sk); return ch; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } return null; } }