java - How to store iv, salt and cipher text? -


from on how achieve password based encryption clear need save salt, iv , cipher text in order decrypt later.

from iv , salt can stored along cipher text

i storing hex value in format

datatypeconverter.printhexbinary(salt) + datatypeconverter.printhexbinary(iv) + datatypeconverter.printhexbinary(ciphertext);

do need store values in binary format ?

datatypeconverter.printbase64binary(salt) + datatypeconverter.printbase64binary(iv) + datatypeconverter.printbase64binary(ciphertext));

output indicates salt , iv ending awful

livyaa/pzg4=fe4gtzucptrkqpuko+z1sa==4/gadioqypoazxr69i0wlc7yfn9/kogitzqpow2y3ms= 

will storing in hex format have effects of data loss ?

will length of iv constant ? in case 32 characters (hexadecimal) or need store length of iv ? salt length fixed 8 bits (16 hexadecimal characters)

(i using pbkdf2withhmacsha1 algorithm key generation , aes/cbc/pkcs5padding cipher)

base64 encodes in chunks of 3 bytes 4 base64 chars. if number of bytes needs encoded ain't multiplum of 3 last block padded 1 or 2 =, indicate block ain't full 3 bytes.

as neither salt nor iv needs kept secret, there ain't problem being able detect start or stop. base64 padding char = ain't problem - ought have way separate 3 encoded strings. e.g. seperate parts :.

the size of iv same block size of encryption algorithm. in case use aes have block size of 128 bits, 16 bytes. give 32 bytes if hex encoded, or 24 bytes if base64 encoded. salt don't have fixed length, , depend on implementation.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -