forked from sirkris/phpMeow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencryption.phpmeow.class.php
75 lines (70 loc) · 1.64 KB
/
encryption.phpmeow.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/*
* phpMeow - A Cute and Fuzzy Alternative to CAPTCHA
* Created by Kris Craig. April - July, 2011.
*
* phpMeow is the first fully-functional, secure
* implementation of KittenAuth in PHP.
*
* This software is open-source and you're free to
* use and/or distribute it as you see fit. See
* LICENSE file for more information.
*
* Get the latest version at: http://www.github.com/sirkris/phpmeow
*/
class phpmeow_encryption
{
function encrypt_string( $text, $use_sessionid = FALSE )
{
require( "config.phpmeow.php" );
/* First, make sure the specified protocol is supported by the PHP install. --Kris */
switch ( $phpmeow_enchash )
{
default:
return FALSE;
break;
case "md5":
if ( !function_exists( "md5" ) )
{
return FALSE;
}
break;
case "sha1":
if ( !function_exists( "sha1" ) )
{
return FALSE;
}
break;
case "sha256":
case "sha512":
if ( !function_exists( "hash" )
|| in_array( $phpmeow_enchash, hash_algos() ) == FALSE )
{
return FALSE;
}
break;
}
if ( $use_sessionid == TRUE )
{
//session_start();
$text = session_id() . $text . self::encrypt_string( session_id(), FALSE );
}
/* Return the encrypted string and we're done! --Kris */
switch ( $phpmeow_enchash )
{
default:
die( "ERROR! Sanity check passed for encrypt_string but functionality for $phpmeow_enchash protocol not added!" );
break;
case "md5":
return md5( $text );
break;
case "sha1":
return sha1( $text );
break;
case "sha256":
case "sha512":
return hash( $phpmeow_enchash, $text );
break;
}
}
}