加密 @param data 待加密数据 @param key 密钥 @return byte[] 加密数据 @throws Exception
(byte[] data, byte[] key)
| 101 | * @throws Exception |
| 102 | */ |
| 103 | public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, BadPaddingException, IllegalBlockSizeException { |
| 104 | |
| 105 | // 还原密钥 |
| 106 | Key k = toKey(key); |
| 107 | |
| 108 | // 实例化 |
| 109 | Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); |
| 110 | |
| 111 | // 初始化,设置为加密模式 |
| 112 | cipher.init(Cipher.ENCRYPT_MODE, k); |
| 113 | |
| 114 | // 执行操作 |
| 115 | return cipher.doFinal(data); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * 生成密钥 <br> |
nothing calls this directly
no test coverage detected