To answer your further questions, when a server is issued and properly configured with a good cert, you shouldn't need to do anything more.
Using HTTPS
HTTPS works by verifying SSL certifications with a Certificate Authority (CA) during an initial handshake. Certificate Authorities, which is essentially a list of signatures that are used to verify said certs, usually come preloaded by an OS vendor.
Assuming your server has a CA issued certificate, all you will be required to do is change from using HTTP to HTTPS when making the connection. The library you're using should have a method of verifying the servers SSL cert, if it doesn't automatically do this for you.
There is no technical reason that you should have to encrypt anything that will being sent over HTTPS, so long as the certificate is strongly encrypted.
Also, if you would like to dig deeper into the nitty-gritty details of how HTTPS works, there's this very good post over on Information Security that sheds a little light on the inner workings of the protocol.
To answer your original question
For the sake of completeness.
PHP has the cryptography extension mcrypt which supports various algorithms and cipher operation modes. I've put together a simple example using AES 256 / PBKDF-SHA1 key decryption (along with the C# code to perform the encryption).
EDIT: I'd like to point out that hash_pbkdf2 is only available in PHP 5.5 and up. Support down to 5.3 can be added with this nifty trick.
PHP
function decode_aes($data, $key) // Decrypt custom format data string
{
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$salt_size = 16;
$iv = substr($data, 0, $iv_size); // Init vector
$salt = substr($data, $iv_size, $salt_size); // The salt
$extact = substr($data, $iv_size + $salt_size); // This is the encrypted data
$key = hash_pbkdf2("sha1", $key, $salt, 1000, 32, true); // Sets to use PBKDF-SHA1
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $extact, MCRYPT_MODE_CBC, $iv); // Perform the decryption with the extracted sections
}
// As an example, I've included this.
$encryped = "zgCp2sSDs32Y8SOn8MYFCEjOJDeM4E3Y8Wx52A+iTFRk/1TJwMzkqmrB06bFu8dK";
echo decode_aes(base64_decode($encryped), "password");
C#
using System;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace AESExample
{
class Program
{
static void Main(string[] args)
{
byte[] toEncrypt = Encoding.UTF8.GetBytes("Encrypted Text");
byte[] key = Encoding.UTF8.GetBytes("password");
String encrypted = Convert.ToBase64String(EncryptAES(toEncrypt, key));
}
public static byte[] EncryptAES(byte[] data, byte[] key)
{
using(RijndaelManaged algo = new RijndaelManaged())
{
algo.GenerateIV();
algo.Mode = CipherMode.CBC;
algo.Padding = PaddingMode.Zeros;
byte[] saltBuffer = new byte[16];
RNGCryptoServiceProvider saltGenerator = new RNGCryptoServiceProvider();
saltGenerator.GetBytes(saltBuffer);
Rfc2898DeriveBytes PBKDF2 = new Rfc2898DeriveBytes(key, saltBuffer, 1000);
key = PBKDF2.GetBytes(32);
ICryptoTransform cipher = algo.CreateEncryptor(key, algo.IV);
using(MemoryStream ms = new MemoryStream())
{
ms.Write(algo.IV, 0, algo.IV.Length);
ms.Write(saltBuffer, 0, saltBuffer.Length);
using(CryptoStream cs = new CryptoStream(ms, cipher, CryptoStreamMode.Write))
{
using(StreamWriter sw = new StreamWriter(cs))
{
sw.Write(Encoding.UTF8.GetString(data).ToCharArray());
}
}
return ms.ToArray();
}
}
}
}
}