1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public static String aesDncode(String content) { try {
SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); random.setSeed("PASSWORD_CRYPT_KEY".getBytes()); KeyGenerator keygen = KeyGenerator.getInstance("AES"); keygen.init(128, random); SecretKey original_key = keygen.generateKey(); byte[] raw = original_key.getEncoded(); SecretKey key = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, key);
byte[] byte_content = Base64.decodeBase64(content);
byte[] byte_decode = cipher.doFinal(byte_content); return new String(byte_decode, StandardCharsets.UTF_8); } catch (NoSuchAlgorithmException | InvalidKeyException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException e) { e.printStackTrace(); }
return null; }
|