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); } 

Reported as a duplicate member by Barmaley java Aug 23 '18 at 2:41 pm

This question has been marked as a duplicate of an existing one.

    1 answer 1

    If I understand the question correctly, the length at the exit for block encryption is always a multiple of the length of the block. In the case of AES, this is 128 bits (16 bytes). Regardless of the encryption mode, the plaintext inside the implementation is padded to the desired length with padding, which varies from 1 to 15 bytes

    • I have a content of 192 characters, and I would like to get a key of the same length on the output, but I get a key of greater length and cannot figure out how to fix it and whether it is possible to fix it at all .. I used extranet.cryptomathic.com/aescalc/ index to encrypt the key manually and I get 192 characters at the output !! - Chizi