javax.crypto is a package in Java that provides cryptographic functionality. The Cipher class in this package defines an encryption, decryption or a key exchange operation. getOutputSize() is a method of the Cipher class that returns the maximum number of bytes that can be produced by the next update or doFinal operation, given the input length.
Code Example 1:
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] input = new byte[1024]; int outputSize = cipher.getOutputSize(input.length); System.out.println(outputSize);
This code initializes a Cipher object with the AES/CBC/PKCS5Padding algorithm, and returns the maximum output size of the Cipher operation if the input was 1024 bytes.
Code Example 2:
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding"); cipher.init(Cipher.DECRYPT_MODE, privateKey); int inputLength = 512; int outputSize = cipher.getOutputSize(inputLength); System.out.println(outputSize);
This code initializes a Cipher object with the RSA/ECB/OAEPWithSHA-256AndMGF1Padding algorithm and returns the maximum output size of the Cipher operation if the input was 512 bytes.
Package Library: javax.crypto.
Java Cipher.getOutputSize - 17 examples found. These are the top rated real world Java examples of javax.crypto.Cipher.getOutputSize extracted from open source projects. You can rate examples to help us improve the quality of examples.