Java tutorial
//package com.java2s; //License from project: Open Source License import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import javax.crypto.Cipher; import javax.crypto.NoSuchPaddingException; public class Main { /** * Constructs a new Cipher. */ public static Cipher newCipher(String algorithm) { try { return Cipher.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException("Not a valid encryption algorithm", e); } catch (NoSuchPaddingException e) { throw new IllegalStateException("Should not happen", e); } } /** * Constructs a new Cipher. */ public static Cipher newCipher(String algorithm, String provider) { try { return Cipher.getInstance(algorithm, provider); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException("Not a valid encryption algorithm", e); } catch (NoSuchPaddingException e) { throw new IllegalStateException("Should not happen", e); } catch (NoSuchProviderException e) { throw new IllegalStateException("Not a valid encryption provider", e); } } }