1

Possible Duplicate:
Best way to use PHP to encrypt and decrypt?

I am new in Two Way crypting technology in PHP. I have used sha512 as one way hashing, but now I really need two way ecryption. and I don't know where to start. Can you tell me which method I must use for the most security? and can you give me simple "hello world" example?

Edited

Thank you for all answers, I found mCrypt as an key for my problem, but I can use a lot of methods like MCRYPT_3DES, MCRYPT_CAST_128, MCRYPT_CAST_256.... so what to use?

4
  • 1
    try searching. There is plenty of information out there on how to do encryption with PHP. Here On SO, On PHP.Net, Another On SO Commented Feb 24, 2012 at 18:00
  • sha512 is one way crypting system, that I use in PHP, I have googled, but is mCrypt installed as default in servers? and which method is most safe from mCrypt methods? Commented Feb 24, 2012 at 18:00
  • @user1228636: No it's not. It's a cryptographic hashing function. See this answer for more info Commented Feb 24, 2012 at 18:01
  • There is plant of methods that I can use in mCrypt, can you suggest me the most secure one? Commented Feb 24, 2012 at 18:04

3 Answers 3

0

You can try using openssl functions for what you need: openssl_public_encrypt and openssl_private_decrypt.

To use them you will have to generate yourself a RSA public/private key pair.

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

1 Comment

Thank you for your answer, but can you suggest 1 or 2 more methods too, to have the choosing opportunity
0

Don't mix up hashing with encryption.

You could use the mcrypt-expansion, its well documented, and they have some good examples, like this one:

 $key = "this is a secret key"; $input = "This is a top secrep message."; $td = mcrypt_module_open('tripledes', '', 'ecb', ''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $key, $iv); $encrypted_data = mcrypt_generic($td, $input); mcrypt_generic_deinit($td); mcrypt_module_close($td); 

There are many other methods out there, openssl is one of them.

2 Comments

I can use a lot of methods like MCRYPT_3DES, MCRYPT_CAST_128, MCRYPT_CAST_256.... so what to use?
Whatever you want. The library supports a few algorithms, see here for more details: mcrypt.hellug.gr/#_mcrypt. Currently it seems to support BLOWFISH, TWOFISH, DES, TripleDES, 3-WAY, SAFER, LOKI97, GOST, RC2, MARS, RIJNDAEL, SERPENT, CAST, ARCFOUR and WAKE. I'm not an expert on the topic, so I'm not sure which one is safer than others (I'd advise against using DES).
0

You could make use of mcrypt which comes with PHP

This is the PHP Manual for Mcrypt (Manual is always the best to start with)

Since you have asked for an easy hello-world type. Have a look here in this link.

1 Comment

Yes there is manual about mCrypt but with mCrypt, I think, I can use a lot of methods like MCRYPT_3DES, MCRYPT_CAST_128, MCRYPT_CAST_256.... so what to use?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.