Java examples for Security:Key
Decrypt a byte array given the same secret key spec used to encrypt the message
//package com.java2s; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; public class Main { /**// www . j a v a2s .co m * Decrypt a byte array given the same secret key spec used to encrypt the message * * @param message * @param skeyspec * @return * @throws Exception */ public static byte[] decrypt(byte[] message, SecretKeySpec skeyspec) throws Exception { Cipher cipher = Cipher.getInstance(skeyspec.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, skeyspec); byte[] decrypted = cipher.doFinal(message); return decrypted; } }