Encrypt and decrypt strings using a PHP key

I am looking for some functions for encrypting and decrypting strings in php using the specified key.

Thank!

+5
source share
4 answers

Start with this: http://www.ibm.com/developerworks/opensource/library/os-php-encrypt/

After that, take a look at Pascal MARTIN’s answer in How do I encrypt a string in PHP?

+3
source

The basic openssl implementation I used before:

class MyEncryption
{

    public $pubkey = '...public key here...';
    public $privkey = '...private key here...';

    public function encrypt($data)
    {
        if (openssl_public_encrypt($data, $encrypted, $this->pubkey))
            $data = base64_encode($encrypted);
        else
            throw new Exception('Unable to encrypt data. Perhaps it is bigger than the key size?');

        return $data;
    }

    public function decrypt($data)
    {
        if (openssl_private_decrypt(base64_decode($data), $decrypted, $this->privkey))
            $data = $decrypted;
        else
            $data = '';

        return $data;
    }
}

RSA. . , . - . . ,

+4
+2

, . mcrypt (, AES, Tripel DES). , - , . 2 ,

0
source

All Articles