This question is an exact duplicate:
Tell me who knows how to get the length of the encrypted key 192 characters ?? Because at the output I get more length, it may be necessary to make some changes to the code. I read quite a few articles and cannot get the desired result because I ran into encryption for the first time using the following method for encrypting
private static byte[] iv = "0000000000000000".getBytes(); public static String encrypt(String content, String key) throws Exception { byte[] input = content.getBytes("utf-8"); MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] thedigest = md.digest(key.getBytes("utf-8")); SecretKeySpec skc = new SecretKeySpec(thedigest, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, skc, new IvParameterSpec(iv)); byte[] cipherText = new byte[cipher.getOutputSize(input.length)]; int ctLength = cipher.update(input, 0, input.length, cipherText, 0); ctLength += cipher.doFinal(cipherText, ctLength); return DatatypeConverter.printHexBinary (cipherText); }