I have the md5 and sha256 hash of a file, I would like to calculate the size of the file from the hash value.
Is there any way to get the size of a file with md5 or sha256 hash of that file available with us ?
Is there any way to get the size of a file with md5 or sha256 hash of that file available with us ?
No, there is no way to determine the size of a file using its hash. That is based on the nature of a hash: same output size for every input size.
32 characters / 128 bits for md5 and 64 characters / 256 bits for sha256
Related
As far as Huffman compression goes, it can compress any files containing ASCII symbols etc. However, is there any maximum limit on the file size?
No, there is no limit. You can string Huffman codes for as long as you like.
Currently in my project, i am required to encrypt a large file of variable size (around 1 to 1.5 GB)
I am using the aes algorithm from the openssl project. But i am not using the entire library, but just a few functions which generate keys from "passwords" and use those keys to encrypt a fixed block of 128 bytes
In short,
void aes_encrypt(char* in, char* out , AES_KEY ekey);
void aes_decrypt(char* in, char* out , AES_KEY dkey);
The main problem now is that these functions work with a block size of 128 bytes only.
So i must write a wrapper function which takes my file and divides it into chunks of 128 bytes, and feed it to these encryption/decryption routines.
So my question is,
In my wrapper, how do i handle the case where the file size is not an
integer multiple of 128
Do i need to pad the encrypted file with 0's to make a multiple of
If this is the case, how do i recognize the amount zero padding i have done, as i understand that just removing the last bits of 0
from a file, may result in the file losing integrity especially if
the file happens to contain a 0 at the end.
Is it a better approach to prepend a header to the encrypted file,
containing the size information of the file and possibly its
checksum.
Thanks.
ps: I am new to encryption(especially AES)
The block length is 128 bit or 16 bytes. You can for example use PKCS7 padding (see section 10.3 of RFC 2315) to make the last block 16 bytes long.
It works like this: if one byte needs to be added you add a byte with value (all values shown in hex) 01, if two bytes need to be added you add two bytes with values 02, and so on. In the case that no padding is required you still have to add a block with 16 padding bytes with value 10.
To remove the padding bytes, just look at the last byte of the file, it gives the number of bytes to remove.
Also note that ECB mode (encrypting blocks independently of each other) is probably not the best to use, have a look at CBC mode as well.
The function RSA_public_encrypt requires that the variable where encrypted text will be saved, should have a length of RSA_size(*rsa) bytes.
Now, I need to know how big could be the text to encrypt, because if I crypt a little string (for example "asdasd"), there's no problem, but if I try with a bigger string, just a portion of it it's crypt.
Assuming you're talking about RSA_public_encrypt(), the docs state it pretty clearly:
flen must be less than RSA_size(rsa) - 11 for the PKCS #1 v1.5 based padding modes, less than RSA_size(rsa) - 41 for RSA_PKCS1_OAEP_PADDING and exactly RSA_size(rsa) for RSA_NO_PADDING.
Remember that these are block cryptos, in the general case you need to split your input into blocks and feed the blocks one at a time to the encryption function.
What is the maximum length of the string that can have md5 hashed? Or: If it has no limit, and if so what will be the max length of the md5 output value?
MD5 processes an arbitrary-length message into a fixed-length output of 128 bits, typically represented as a sequence of 32 hexadecimal digits.
The length of the message is unlimited.
Append Length
A 64-bit representation of b (the length of the message before the
padding bits were added) is appended to the result of the previous
step. In the unlikely event that b is greater than 2^64, then only
the low-order 64 bits of b are used.
The hash is always 128 bits. If you encode it as a hexdecimal string you can encode 4 bits per character, giving 32 characters.
MD5 is not encryption. You cannot in general "decrypt" an MD5 hash to get the original string.
See more here.
You can have any length, but of course, there can be a memory issue on the computer if the String input is too long. The output is always 32 characters.
The algorithm has been designed to support arbitrary input length. I.e you can compute hashes of big files like ISO of a DVD...
If there is a limitation for the input it could come from the environment where the hash function is used. Let's say you want to compute a file and the environment has a MAX_FILE limit.
But the output string will be always the same: 32 hex chars (128 bits)!
A 128-bit MD5 hash is represented as a sequence of 32 hexadecimal digits.
You may want to use SHA-1 instead of MD5, as MD5 is considered broken.
You can read more about MD5 vulnerabilities in this Wikipedia article.
There is no limit to the input of md5 that I know of. Some implementations require the entire input to be loaded into memory before passing it into the md5 function (i.e., the implementation acts on a block of memory, not on a stream), but this is not a limitation of the algorithm itself. The output is always 128 bits. Note that md5 is not an encryption algorithm, but a cryptographic hash. This means that you can use it to verify the integrity of a chunk of data, but you cannot reverse the hashing.
Also note that md5 is considered broken, so you shouldn't use it for anything security-related (it's still fine to verify the integrity of downloaded files and such).
md5 algorithm appends the message length to the last 64 bits of the last block, thus it would be fair to say that the message can be 2^64 bits long (18 e18 bits).
Max length for MD5 input : largest definable and usable stream of bit
A stream of bit definition constraints can depend on operating system, hardware constraints, programming language and more...
Length for MD5 output : Fixed-length always 128 bits
For easier display, they are usually displayed in hex, which because each hex digit (0-1-2-3-4-5-6-7-8-9-A-B-C-D-E-F) takes up 4 bits of space, so its output can be displayed as 32 hex digits.
128 bits = 16 bytes = 32 hex digits
The md5 output is always 32 characters.Therefore, when setting character limit for the password in the database, do not give a value below 32 characters. If you give a value below 32, the password will be incompletely recorded in the database and therefore users will encounter an error while logging into the system.
I want to know if there exists a way to differentiate a md5 hashcode of a sha-1 hashcode?
For example:
d41d8cd98f00b204e9800998ecf8427e
da39a3ee5e6b4b0d3255bfef95601890afd80709
How could I know which are encrypted in md5 and which are not? Is it possible?
I'm not quite sure if this is what you're asking, but MD5 is 128 bits/32 hex digits, while SHA-1 is 160 bits/40 hex digits, so it's fairly easy to tell the difference between them (providing, of course, that you know that your hashes will be either MD5 or SHA-1 and not something else).
(If you're asking whether you can determine if a given MD5 hash is a hash of a hash or a hash of some other data, then I believe the answer is "no".)
MD5 gives a 128-bit hash value.
SHA-1 gives a 160-bit hash value.