2

I am encrypting some data from codeigniter using Encrypt class and this will be send to a java program and need to be decoded there.

php code:

    $this->load->library('encrypt');
    $this->encrypt->set_key(SERVER_ENCRYPT_KEY);
    $this->encrypt->set_mode(MCRYPT_MODE_CFB);
    $this->data = $this->encrypt->encode($this->input->post('data'));

where SERVER_ENCRYPT_KEY is the key.

I found this: MCrypt for Java but I could not make it work. There are other libs that can do this? or maybe an example how to do this using the java version of MCrypt.

2 Answers 2

1

Take a look in the CI_Encrypt class. In addition to calling the mcrypt library, it does various non standard things. As an example it runs encrypted data through an own invented _add_cipher_noise method. Also, it seems that the encrypted format have changed with different versions - indicating that this could happen again.

If you are going to use the encrypted data outside codeignite you should not use what looks like codeignites own packaging of mcrypt encrypted data.

Sign up to request clarification or add additional context in comments.

3 Comments

I saw that noise added on encryption and I did the same on java too, but I was wondering if someone did managed to use encrypted data outside of codeigniter. I am trying this to avoid asking +10k customers to reenter some data again. But maybe at the end I will end up in applying an custom encryption method in both sides.
Notice that the messages you get from the encode call in codeigniter ain't self contained. You need to know upfront what cipher was used to encrypt, when you decrypt. The user might have used a $this->encrypt->set_cipher(); and you can't deduct that from the message. Also, if mcrypt ain't there, it falls back to some other method - this also needs to be handled.
Are used the default values MCRYPT_RIJNDAEL_256 for cipher and MCRYPT_MODE_CBC for mcrypt mode. Also the mcrypt is installed.
1

I decided to avoid CI_Encrypt and use this PHP-Java-AES-Encrypt with small changes: add noise and use 2 types of keys. Also I build a tool to convert the old encrypted data to the new format.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.