The last essay left a question, the two kinds of encryption results are different?
In fact, the internal implementation is not the same way, see the notes
1 /**2 * provide keys and vectors for encryption3 *4 * @paramSSRC5 * @paramKey6 * @paramIV7 * @return8 * @throwsException9 */Ten Public StaticString Encrypt (String sSrc,byte[] Key,byte[] IV)throwsException { OneSecretkeyspec Skeyspec =NewSecretkeyspec (Key, "AES");//constructs a key based on a given byte array ACipher Cipher = cipher.getinstance ("aes/cbc/pkcs5padding");//"algorithm/Mode/complement Method" -Ivparameterspec _iv =NewIvparameterspec (iv);//using CBC mode, a vector IV is required to increase the strength of the encryption algorithm -Cipher.init (Cipher.encrypt_mode, Skeyspec, _iv);//initializes this Cipher with a key and a set of algorithm parameters the byte[] encrypted = Cipher.dofinal (Ssrc.getbytes ("Utf-8"));//encrypt or decrypt data by one-part operation, or end a multipart operation. - returnbase64.encodebase64string (encrypted); -}
1 /**2 * Encryption3 * @paramcontent4 * @paramkeybytes5 * @paramIV6 * @return7 * @throwsException8 */9 PublicString Aes_cbc_encrypt (byte[] content,byte[] keybytes,byte[] IV)throwsexception{Ten Try{ OneKeygenerator keygenerator= keygenerator.getinstance ("AES");//returns the Keygenerator object that generates the secret key for the specified algorithm AKeygenerator.init (128,NewSecureRandom (keybytes));//initializes this key generator with a user-supplied random source that has a determined key size -Secretkey Key=keygenerator.generatekey ();//generates a key. -Cipher cipher=cipher.getinstance ("aes/cbc/pkcs5padding"); theCipher.init (Cipher.encrypt_mode, Key,NewIvparameterspec (iv)); - byte[] result=cipher.dofinal (content); - returnbase64.encodebase64string (result); -}Catch(Exception e) { + e.printstacktrace (); - Throwe; + } A}
JAVA AES Plus decryption detailed