Re: How to encrypt a string in php ?

Alles, was PHP betrifft, kann hier besprochen werden.

Re: How to encrypt a string in php ?

Postby Jerrypetersons » 19. October 2010 13:36

Hi,

you can use the crypt() PHP function to encrypt the string .

For e.g.,

<?php
$Str = crypt('demostring');
print $Str. “ is the encrypted version of demostring”;
?>

its only one encryption algorithm. we can decrypt the string by using this function.
crypt() function used DEC algorithm.
Jerrypetersons
 
Posts: 2
Joined: 19. October 2010 13:19

Re: How to encrypt a string in php ?

Postby kevinedenmarg » 28. November 2010 13:12

Well, there are some pretty good libraries out there. I think it is easy to see how to use this function.If you want secure passwords, the best way would be to use some very resilient hashing algorithm.
kevinedenmarg
 
Posts: 3
Joined: 28. November 2010 12:33

Re: How to encrypt a string in php ?

Postby steven_elvisda » 04. March 2011 16:08

is there any method that can we create encryption code by ourself? I had tried with with md5() but I could not decryption it back for password.
could you please give me and idea all?

Kindly Regards,
Steve.
steven_elvisda
 
Posts: 2
Joined: 04. March 2011 15:26

Re: How to encrypt a string in php ?

Postby WilliL » 04. March 2011 17:30

I use RC4 de/encryption http://en.wikipedia.org/wiki/RC4 in these cases.
you'll find pure php-code http://php.net/manual/de/ref.mcrypt.php
reason: it works with special german letters.

With passwords I use md5 / sha (no decryption). In my database the hashed password+salt is saved.
Willi
WilliL
 
Posts: 619
Joined: 08. January 2010 10:54
XAMPP Version: 5.5.19
Operating System: Win7Home Prem 64 SP1

Re: How to encrypt a string in php ?

Postby johnwright456 » 31. May 2011 10:39

Try this code.....


<?php
// String EnCrypt + DeCrypt function
// Author: halojoy, July 2006
function convert($str,$ky=''){
if($ky=='')return $str;
$ky=str_replace(chr(32),'',$ky);
if(strlen($ky)<8)exit('key error');
$kl=strlen($ky)<32?strlen($ky):32;
$k=array();for($i=0;$i<$kl;$i++){
$k[$i]=ord($ky{$i})&0x1F;}
$j=0;for($i=0;$i<strlen($str);$i++){
$e=ord($str{$i});
$str{$i}=$e&0xE0?chr($e^$k[$j]):chr($e);
$j++;$j=$j==$kl?0:$j;}
return $str;
}
///////////////////////////////////

// Secret key to encrypt/decrypt with
$key='mysecretkey'; // 8-32 characters without spaces

// String to encrypt
$string1='To be or not to be, that is the question';

// EnCrypt string
$string2=convert($string1,$key);

// DeCrypt back
$string3=convert($string2,$key);

// Test output
echo '<span style="font-family:Courier">'."\n";
echo 'Key: '.$key.'<br>'."\n";
echo $string1.'<br>'."\n";
echo $string2.'<br>'."\n";
echo $string3.'<br>'."\n";
echo '</span>'."\n";
?>
johnwright456
 
Posts: 3
Joined: 31. May 2011 10:28


Return to PHP

Who is online

Users browsing this forum: No registered users and 4 guests