Picking encryption cipher for mcrypt

Posted by Autolycus on Stack Overflow See other posts from Stack Overflow or by Autolycus
Published on 2010-11-08T22:01:09Z Indexed on 2013/11/02 3:54 UTC
Read the original article Hit count: 107

Filed under:
|

I have few questions about this code:

<?php 
   $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); 
   $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); 
   $key = "This is a very secret key"; 
   $text = file_get_contents('path/to/your/file'); 
   echo strlen($text) . "\n"; 

   $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv); 
   file_put_contents('path/to/your/file', $crypttext);    
?> 

It encrypts the file just fine, however it adds additional nulls at the end, so if I encrypt:

 a test string is this one
    and here is a new line 

once decrypted becomes:

a test string is this one
    and here is a new line 000000000000000

What's going on?

Second, is MCRYPT_RIJNDAEL_256 compatible with AES-128?

Finally, how would I let another party decrypt a file I've encrypted? They would need to know which encryption was used and I am not sure what to tell them.

© Stack Overflow or respective owner

Related posts about php

Related posts about encryption