Foros del Web » Programando para Internet » PHP »

encriptar y desencriptar con una llave?

Estas en el tema de encriptar y desencriptar con una llave? en el foro de PHP en Foros del Web. lo q pasa es q estoy buscando un metodo para almacenar datos provenientes de un array a un archivo de texto. lo primero que hice ...
  #1 (permalink)  
Antiguo 19/09/2004, 07:50
Avatar de ArrauKano  
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago
Mensajes: 664
Antigüedad: 21 años, 5 meses
Puntos: 4
encriptar y desencriptar con una llave?

lo q pasa es q estoy buscando un metodo para almacenar datos provenientes de un array a un archivo de texto.
lo primero que hice fue serializar el array en una cadena, pero ahora me gustaría dejarlo lo + ilegible posibe, y se e ocurrió q por hay en php deben existir algunas funciones q manipulen la cadena para dejarlo "pseudo-encriptada".

pense entonces, que tal si mi sitio tuviera una password a modo de llave para encriptar y desencriptar sus propios datos? de modo q si algun malintencionado logra vr o bajar el datafile no encuentre como hacerlo visible a menos q consiga la llave.

como puedo hacer esto?
  #2 (permalink)  
Antiguo 19/09/2004, 16:10
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Puedes usar las librerias:

Mcrypt()
http://www.php.net/mcrypt

Y sino, .. create tu própio algorítmo (con tu própia semilla) para encriptar/desencriptar .. o mira alguno ya hecho en:

http://phpclasses.promoxy.com/browse/class/20.html

Un saludo,
  #3 (permalink)  
Antiguo 23/06/2005, 15:21
 
Fecha de Ingreso: febrero-2004
Mensajes: 1.987
Antigüedad: 20 años, 2 meses
Puntos: 22
Pero profesor,

a mi me ha ido remal con el MyCRIPT.

Si me corre pero:

http://www.forosdelweb.com/f18/dame-ejemplo-mcrypt-298128/
  #4 (permalink)  
Antiguo 23/06/2005, 15:25
Avatar de dwaks  
Fecha de Ingreso: agosto-2002
Ubicación: Panamá
Mensajes: 962
Antigüedad: 21 años, 8 meses
Puntos: 15
Te invito a usar una funcion que cree hace tiempito ya, se encuentra en mi firma se llama FUNCION ENCRYPT() usa un key de server y no puede ser visto lo que encrypta en otro servidor.

Saludos,
  #5 (permalink)  
Antiguo 23/06/2005, 16:14
 
Fecha de Ingreso: febrero-2004
Mensajes: 1.987
Antigüedad: 20 años, 2 meses
Puntos: 22
Gracias,

buen intento pero aun nova, sin procesar nada:
Código PHP:
NoticeUninitialized string offset9 in c:000errorencryptFunction.php on line 132

Notice
Undefined variablekey in c:000errorencryptFunction.php on line 133

Notice
Uninitialized string offset9 in c:000errorencryptFunction.php on line 132

Notice
Undefined variablekey in c:000errorencryptFunction.php on line 133

Notice
Uninitialized string offset9 in c:000errorencryptFunction.php on line 132

Notice
Undefined variablekey in c:000errorencryptFunction.php on line 133

Notice
Undefined variabletemp in c:000errorencryptFunction.php on line 71

Notice
Undefined offset1 in c:000errorencryptFunction.php on line 71

Notice
Undefined offset2 in c:000errorencryptFunction.php on line 71

Notice
Undefined offset3 in c:000errorencryptFunction.php on line 71

Notice
Undefined offset4 in c:000errorencryptFunction.php on line 71

Notice
Undefined offset5 in c:000errorencryptFunction.php on line 71


... Etc... 
Procesando [email protected] no devuelve el valor.

Salu2!.
  #6 (permalink)  
Antiguo 23/06/2005, 16:35
 
Fecha de Ingreso: febrero-2004
Mensajes: 1.987
Antigüedad: 20 años, 2 meses
Puntos: 22
A este hombre tampoco le fue muy bien...
Código PHP:
<? 
/* ----------------------------------------------- 
@Author: Developped by [email protected] 
@Site: http://www.EZScripts.net/ 
----------------------------------------------- 

How's the my encryption algorithm work: 

First it will generate an encryption key with the string you supply: 

Key 1 will be equal to the numerical value 
of each character in your crypt key. 

Key 2 will be equal to the length of your 
crypt key. 

For each character in the string you wish to encrypt, it will do the following mathematical calculations, where V is the final value of the encoded character and C is the value of the character currently encrypting: 

V = C * Key1 
V = V + Key2 

It will then separate each character in the original string with a character between 65 and 90 (cap. letters). 

To decrypt the string, it will do the opposite calculations, where V is the final value of the decrypted character and C is the value of the encrypted character: 

V = V / Key1 
V = C – Key2 */ 

/* ----------------------------------------------- 
@Name: Encrypt() 
@Args: $txt-> String to encrypt. 
@Args: $CRYPT_KEY -> String used to generate a encryption key. 
@Returns: $estr -> Encrypted string. 
----------------------------------------------- */ 

function encrypt($txt,$CRYPT_KEY){ 
if (!
$txt && $txt != "0"){ 
return 
false
exit; 


if (!
$CRYPT_KEY){ 
return 
false
exit; 


$kv keyvalue($CRYPT_KEY); 
$estr ""
$enc ""

for (
$i=0$i<strlen($txt); $i++){ 
$e ord(substr($txt$i1)); 
$e $e $kv[1]; 
$e $e $kv[2]; 
(double)
microtime()*1000000
$rstr chr(rand(6590)); 
$estr .= "$rstr$e"


return 
$estr


/* ----------------------------------------------- 
@Name: Decrypt() 
@Args: $txt-> String to decrypt. 
@Args: $CRYPT_KEY -> String used to encrypt the string. 
@Returns: $estr -> Decrypted string. 
----------------------------------------------- */ 

function decrypt($txt$CRYPT_KEY){ 
if (!
$txt && $txt != "0"){ 
return 
false
exit; 


if (!
$CRYPT_KEY){ 
return 
false
exit; 


$kv keyvalue($CRYPT_KEY); 
$estr ""
$tmp ""

for (
$i=0$i<strlen($txt); $i++) { 
if ( 
ord(substr($txt$i1)) > 64 && ord(substr($txt$i1)) < 91 ) { 
if (
$tmp != "") { 
$tmp $tmp $kv[2]; 
$tmp $tmp $kv[1]; 
$estr .= chr($tmp); 
$tmp ""

} else { 
$tmp .= substr($txt$i1); 



$tmp $tmp $kv[2]; 
$tmp $tmp $kv[1]; 
$estr .= chr($tmp); 

return 
$estr

/* ----------------------------------------------- 
@Name: keyvalue() 
@Args: $CRYPT_KEY -> String used to generate a encryption key. 
@Returns: $keyvalue -> Array containing 2 encryption keys. 
----------------------------------------------- */ 

function keyvalue($CRYPT_KEY){ 
$keyvalue ""
$keyvalue[1] = "0"
$keyvalue[2] = "0"
for (
$i=1$i<strlen($CRYPT_KEY); $i++) { 
$curchr ord(substr($CRYPT_KEY$i1)); 
$keyvalue[1] = $keyvalue[1] + $curchr
$keyvalue[2] = strlen($CRYPT_KEY); 

return 
$keyvalue


    
$a='asdqwe';
    echo 
encrypt($a,5);
    
$b='N0S0E0P0W0V0';
    echo 
'<hr>';
    echo 
decrypt($b,5);
exit;
?>
Si alguien lo entiende y puede corregirlo, por favor piblicarlo.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:43.