Here you can find the source of encryptAes(String value)
public static String encryptAes(String value) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
//package com.java2s; /******************************************************************************* * Copyright (c) 2011, 2016 Eurotech and/or its affiliates and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:// w w w . j a va 2 s . c o m * Eurotech - initial API and implementation * *******************************************************************************/ import java.security.InvalidKeyException; import java.security.Key; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.SecretKeySpec; import javax.xml.bind.DatatypeConverter; public class Main { private static final String ALGORITHM = "AES"; private static final byte[] SECRET_KEY = "ipsea1s214d5a6sfs8dfsdg@$%3saf".getBytes(); public static String encryptAes(String value) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { Key key = generateKey(); Cipher c = Cipher.getInstance(ALGORITHM); c.init(Cipher.ENCRYPT_MODE, key); byte[] encryptedBytes = c.doFinal(value.getBytes()); String encryptedValue = DatatypeConverter.printBase64Binary(encryptedBytes); return encryptedValue; } private static Key generateKey() { Key key = new SecretKeySpec(SECRET_KEY, ALGORITHM); return key; } }