Here you can find the source of decryptBytes(byte[] data, byte[] key)
Parameter | Description |
---|---|
data | - Information to be decrypted. |
key | - Key to use for decryption. |
public static byte[] decryptBytes(byte[] data, byte[] key)
//package com.java2s; import java.security.InvalidKeyException; 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; public class Main { /**/*from w w w . jav a 2s. c o m*/ * Decrypts data using the AES encryption cipher. * * @param data * - Information to be decrypted. * @param key * - Key to use for decryption. * @return The decrypted data. */ public static byte[] decryptBytes(byte[] data, byte[] key) { try { Cipher cipher = Cipher.getInstance("AES"); SecretKeySpec sKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.DECRYPT_MODE, sKey); return cipher.doFinal(data); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } return null; } }