As the title asks. OpenSSL will pad stuff with PKCS5 if you encrypt something, however is there a way to access this feature without encrypting something?
migrated from crypto.stackexchange.com Oct 30 '13 at 12:19
This question came from our site for software developers, mathematicians and others interested in cryptography.
PKCS#5 padding is defined relatively to the block size of the underlying block cipher. If there is no block cipher, then there is no block size, and thus the padding is ill-defined.
Nevertheless, if you take as extra input the block size s to use, then the padding is not hard to implement. If the data length is n, then the padding adds exactly k bytes, such that:
These rules make the padding unambiguous. There is exactly one solution for k, given by the equation: k = s - (n mod s). Here is an ugly shell script (for Linux) which adds the padding to an input file:
(use the input file name as first parameter and the block size as second parameter; the padded file is written on the standard output.)
The reverse operation is left as an exercise (shell programming is not very adequate for this sort of treatment).