Last active
July 19, 2019 18:04
-
-
Save parzibyte/ea8668afaa8101f561c5ea56a00083fe to your computer and use it in GitHub Desktop.
Crypt data with PHP using php-encryption https://parzibyte.me/blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def0000033794dc126bf1be7994dab4ec8db7dcd8efb32308a70fa592b7a41cb231494dc6a1689639b006796bec780132bbfa1c7b7415d15d8c797ca107b86e74e9e3cba |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Cifrar datos con PHP usando php-encryption | |
* | |
* https://parzibyte.me/blog | |
* | |
*/ | |
require_once "vendor/autoload.php"; | |
use Defuse\Crypto\Crypto; | |
use Defuse\Crypto\Key; | |
// Este mensaje puede venir de otro lugar | |
$mensajeSecreto = "Encriptando con PHP desde parzibyte.me"; | |
// No olvides guardar la clave en un lugar seguro; aquí lo pongo así de simple para ejemplos de | |
// simplicidad | |
$contenido = file_get_contents("clave.txt"); | |
// Cargar la clave desde una cadena ASCII (pues la clave no es tan legible ni entendible como una simple cadena) | |
$clave = Key::loadFromAsciiSafeString($contenido); | |
// Y ya podemos cifrar datos | |
$mensajeCifrado = Crypto::encrypt($mensajeSecreto, $clave); | |
// Este mensaje ya está cifrado; puedes guardarlo en la base de datos ;) | |
echo $mensajeCifrado; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment