converts a byte[] that originally was created using {@link SecretKey#getEncoded()} back to the corresponding
instance.

Example: CipherUtils.deserializeSecretKey(data, "AES")
509139
public static SecretKey deserializeSecretKey(byte[] keyData, String algorithm) {
        LOGGER.trace("deserialize secret key from data using algorithm \"{}\"", algorithm);
        return new SecretKeySpec(keyData, algorithm);
    }
30928
public byte[] decrypt(byte[] msg) {
        if (msg == null) return null;
        try {
            Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM_IMPLEMENTATION);
            SecretKeySpec key = new SecretKeySpec(getMd5(), ENCRYPTION_ALGORITHM);
            IvParameterSpec iv = new IvParameterSpec(getIv());
            cipher.init(Cipher.DECRYPT_MODE, key, iv);
            return cipher.doFinal(msg);
        } catch (Exception e) {
            return null;
        }
    }
892379
private byte[] decrypt(final byte[] bytes) throws IOException {
        if (bytes.length < CcAes.BLOCK << 1) {
            throw new DecodingException("Invalid encrypted message format");
        }
        try {
            final byte[] vector = new byte[CcAes.BLOCK];
            final byte[] message = new byte[bytes.length - vector.length];
            System.arraycopy(bytes, 0, vector, 0, vector.length);
            System.arraycopy(
                bytes,
                vector.length,
                message,
                0,
                message.length
            );
            return this.cipher(
                Cipher.DECRYPT_MODE,
                new IvParameterSpec(vector)
            ).doFinal(message);
        } catch (final BadPaddingException | IllegalBlockSizeException ex) {
            throw new DecodingException(ex);
        }
    }
1229099
ByteBuffer decryptChunk(ByteBuffer ciphertextChunk, SecretKey fileKey) {
		assert ciphertextChunk.remaining() >= NONCE_SIZE + MAC_SIZE;

		try {
			// nonce:
			final byte[] nonce = new byte[NONCE_SIZE];
			final ByteBuffer chunkNonceBuf = ciphertextChunk.asReadOnlyBuffer();
			chunkNonceBuf.position(0).limit(NONCE_SIZE);
			chunkNonceBuf.get(nonce);

			// payload:
			final ByteBuffer payloadBuf = ciphertextChunk.asReadOnlyBuffer();
			payloadBuf.position(NONCE_SIZE).limit(ciphertextChunk.limit() - MAC_SIZE);

			// payload:
			final Cipher cipher = CipherSupplier.AES_CTR.forDecryption(fileKey, new IvParameterSpec(nonce));
			final ByteBuffer outBuf = ByteBuffer.allocate(cipher.getOutputSize(payloadBuf.remaining()));
			cipher.doFinal(payloadBuf, outBuf);

			// flip and return:
			outBuf.flip();
			return outBuf;
		} catch (ShortBufferException e) {
			throw new IllegalStateException("Buffer allocated for reported output size apparently not big enough.", e);
		} catch (IllegalBlockSizeException | BadPaddingException e) {
			throw new IllegalStateException("Unexpected exception for CTR ciphers.", e);
		}
	}
1218504
@Override
	public byte[] aesDecrypt(byte[] data, int offset, int length, byte[] key,
			byte[] initVector) throws CryptoException {
		try {
			SecretKeySpec scs = new SecretKeySpec(key, "AES");
			Cipher cipher = Cipher.getInstance("AES/CFB/NoPadding", "ZBC");
			IvParameterSpec iv = new IvParameterSpec(initVector);
			ByteArrayOutputStream baos = new ByteArrayOutputStream(length);
			cipher.init(Cipher.DECRYPT_MODE, scs, iv);
			CipherOutputStream out = new CipherOutputStream(baos, cipher);
			out.write(data, offset, length);
			out.close();
			baos.close();
			return baos.toByteArray();
		} catch (Exception e) {
			throw new CryptoException(e);
		}
	}
928737
public byte[] decrypt(byte[] bytes) {
		lock.lock();
		try {
			if (null == this.params) {
				cipher.init(Cipher.DECRYPT_MODE, secretKey);
			} else {
				cipher.init(Cipher.DECRYPT_MODE, secretKey, params);
			}
			return cipher.doFinal(bytes);
		} catch (Exception e) {
			throw new CryptoException(e);
		} finally {
			lock.unlock();
		}
	}
351541
public static byte[] decrypt(byte[] cipherBytes) {
		try {
//			byte[] cipherBytes = toBytes(cipherText);
			Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING", "SunJCE");
			SecretKeySpec key = new SecretKeySpec(ENCRYPTION_KEY.getBytes("UTF-8"), "AES");
			cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(IV.getBytes("UTF-8")));
			return cipher.doFinal(cipherBytes);
		} catch (Exception e) {
			throw new JKSecurityException(e);
		}
	}
1298020
final byte[] crypto(final byte[] input, final int offset, final int len, final boolean decrypt)
			throws InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException,
			BadPaddingException {
		aesCipher.init(decrypt ? Cipher.DECRYPT_MODE : Cipher.ENCRYPT_MODE, aesKey, aesIV);
		return aesCipher.doFinal(input, offset, len);
	}
1027607
public static byte[] generateKey()
        throws GeneralSecurityException
    {
        KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM);
        // java max 128
        keyGenerator.init(128);
        SecretKey secretKey = keyGenerator.generateKey();
        return secretKey.getEncoded();
    }
221564
public Map<String, String> decode(byte[] bytes) throws DeserializationException {
        Map<String, String> map = new HashMap<String, String>();
        if (bytes == null || bytes.length == 0) {
            return map;
        }

        UnsafeByteArrayInputStream in = new UnsafeByteArrayInputStream(bytes);
        try {
            while (in.available() > 0) {
                String key = readString(in);
                String value = readString(in);
                map.put(key, value);
            }
            return map;
        } catch (IOException ex) {
            throw new DeserializationException(ex.getMessage(), ex);
        }
    }
998045
public static byte[] decryptBase64DES(byte[] data, byte[] key) {
        try {
            return decryptDES(Base64.getDecoder().decode(data), key);
        } catch (Exception e) {
            return null;
        }
    }
224369
public byte[] decrypt(byte[] cipherData) throws SignatureException {
    checkArgument(cipherData.length >= OVERHEAD_SIZE,
        "Invalid cipherData, %s bytes", cipherData.length);

    // workBytes := initVector || E(payload) || I(signature)
    byte[] workBytes = cipherData.clone();
    ByteBuffer workBuffer = ByteBuffer.wrap(workBytes);
    boolean success = false;

    try {
      // workBytes := initVector || payload || I(signature)
      xorPayloadToHmacPad(workBytes);
      // workBytes := initVector || payload || I'(signature)
      int confirmationSignature = hmacSignature(workBytes);
      int integritySignature = workBuffer.getInt(workBytes.length - SIGNATURE_SIZE);
      workBuffer.putInt(workBytes.length - SIGNATURE_SIZE, confirmationSignature);

      if (confirmationSignature != integritySignature) {
        throw new SignatureException("Signature mismatch: "
            + Integer.toHexString(confirmationSignature)
            + " vs " + Integer.toHexString(integritySignature));
      }

      if (logger.isDebugEnabled()) {
        logger.debug(dump("Decrypted", cipherData, workBytes));
      }

      success = true;
      return workBytes;
    } finally {
      if (!success && logger.isDebugEnabled()) {
        logger.debug(dump("Decrypted (failed)", cipherData, workBytes));
      }
    }
  }
684887
private byte[] encryptInternal(SecretKeySpec key, String toEncrypt) {
        try {
            Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM + ENCRYPTION_ALGORITHM_MODIFIER);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            return cipher.doFinal(toEncrypt.getBytes(ENCODING));
        } catch (GeneralSecurityException e) {
            throw new RuntimeException("Exception during decryptInternal: " + e, e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Exception during encryptInternal: " + e, e);
        }
    }
943200
public static byte[] generateKey() {
        CipherKeyGenerator cipherKeyGenerator = new CipherKeyGenerator();
        cipherKeyGenerator.init(new KeyGenerationParameters(new SecureRandom(), 128));
        return cipherKeyGenerator.generateKey();
    }
1321123
synchronized static private byte[] getSecret() throws Exception {
		if( null == secret ) {
			Date now = new Date();
			long nowValue = now.getTime();
			
			byte[] nowBytes = new byte[8];
			nowBytes[0] = (byte)((nowValue >>  0) & 0xff);
			nowBytes[1] = (byte)((nowValue >>  8) & 0xff);
			nowBytes[2] = (byte)((nowValue >> 16) & 0xff);
			nowBytes[3] = (byte)((nowValue >> 24) & 0xff);
			nowBytes[4] = (byte)((nowValue >> 32) & 0xff);
			nowBytes[5] = (byte)((nowValue >> 40) & 0xff);
			nowBytes[6] = (byte)((nowValue >> 48) & 0xff);
			nowBytes[7] = (byte)((nowValue >> 56) & 0xff);
			
			MessageDigest md = MessageDigest.getInstance("SHA");
			md.update( nonce );
			md.update( nowBytes );
			secret = md.digest();
		}
		
		return secret;
	}
893022
public static byte[] encrypt(byte[] data, byte[] key) throws InvalidCipherTextException {
        checkNotNull(data);
        checkNotNull(key);
        AESFastEngine aesEngine = new AESFastEngine();
        PaddedBufferedBlockCipher cipher =
                new PaddedBufferedBlockCipher(aesEngine, new PKCS7Padding());
        cipher.init(true, new KeyParameter(key));
        byte[] outBuf = new byte[cipher.getOutputSize(data.length)];
        int l1 = cipher.processBytes(data, 0, data.length, outBuf, 0);
        int l2 = cipher.doFinal(outBuf, l1);
        byte[] result;
        if (outBuf.length != l1 + l2) {
            result = new byte[l1 + l2];
            System.arraycopy(outBuf, 0, result, 0, result.length);
        } else
            result = outBuf;
        return result;
    }
1186102
public static byte[] initKey() throws Exception{
		//密钥生成器
		KeyGenerator keyGen = KeyGenerator.getInstance("AES");
		//初始化密钥生成器
		keyGen.init(128);  //默认128，获得无政策权限后可用192或256
		//生成密钥
		SecretKey secretKey = keyGen.generateKey();
		return secretKey.getEncoded();
	}