Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active July 19, 2019 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/ea8668afaa8101f561c5ea56a00083fe to your computer and use it in GitHub Desktop.
Save parzibyte/ea8668afaa8101f561c5ea56a00083fe to your computer and use it in GitHub Desktop.
Crypt data with PHP using php-encryption https://parzibyte.me/blog
def0000033794dc126bf1be7994dab4ec8db7dcd8efb32308a70fa592b7a41cb231494dc6a1689639b006796bec780132bbfa1c7b7415d15d8c797ca107b86e74e9e3cba
<?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