KPO
KPO

Reputation: 880

How to encrypt data at rest?

HOw do i encrypt data at rest? I know SSL encrypts in transit.

How do i integrate AES 256 bit encryption in phpmyadmin?

Upvotes: 0

Views: 2144

Answers (2)

rzetterberg
rzetterberg

Reputation: 10268

Here's an example using mcrypt:

<?
// Encrypt Function
function mc_encrypt($encrypt, $mc_key) {
    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
    $passcrypt = trim(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $mc_key, trim($encrypt), MCRYPT_MODE_ECB, $iv));
    $encode = base64_encode($passcrypt);
    return $encode;
}

// Decrypt Function
function mc_decrypt($decrypt, $mc_key) {
    $decoded = base64_decode($decrypt);
    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
    $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $mc_key, trim($decoded), MCRYPT_MODE_ECB, $iv));
    return $decrypted;
}
?>

Read more about the library here: http://php.net/manual/en/ref.mcrypt.php

EDIT:

If i misunderstood the question and you wanted to do this in mysql you can use the mysql built in aes encryption functions:

INSERT INTO users SET name = "User1", password = AES_ENCRYPT("password", "encryption key");

and:

SELECT AES_DECRYPT(password, "encryption key") FROM users WHERE id = 1;

However this is just aes128, if you want to use aes256 directly in mysql you would have to modify the source and recompile.

Read more about it here:

http://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html#function_aes-encrypt

Upvotes: 1

cusimar9
cusimar9

Reputation: 5259

If you're talking about straight encrypt/decrypt of data then there are some good examples in the php.net manuals.

You would then encrypt your data before inserting it into your database, you wouldn't encrypt anything through phpMyAdmin.

Upvotes: 1

Related Questions