public static long ciphertextSize ( long cleartextSize , Cryptor cryptor ) { checkArgument ( cleartextSize >= 0 , "expected cleartextSize to be positive, but was %s" , cleartextSize ) ; long cleartextChunkSize = cryptor . fileContentCryptor ( ) . cleartextChunkSize ( ) ; long ciphertextChunkSize = cryptor . fileContentCryptor ( ) . ciphertextChunkSize ( ) ; long overheadPerChunk = ciphertextChunkSize - cleartextChunkSize ; long numFullChunks = cleartextSize / cleartextChunkSize ; // floor by int-truncation long additionalCleartextBytes = cleartextSize % cleartextChunkSize ; long additionalCiphertextBytes = ( additionalCleartextBytes == 0 ) ? 0 : additionalCleartextBytes + overheadPerChunk ; assert additionalCiphertextBytes >= 0 ; return ciphertextChunkSize * numFullChunks + additionalCiphertextBytes ; }
Calculates the size of the ciphertext resulting from the given cleartext encrypted with the given cryptor .