A Selection Riptide Tempora's Security Library - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-30-2011, 06:03 PM   #1 (permalink)
Junior Member
 
RiptideTempora's Avatar
 
Join Date: Nov 2011
Location: Orlando, FL
Posts: 3
Default A Selection Riptide Tempora's Security Library

Encryption and security are interesting subjects-- both far beyond the scope of any forum post I could ever write. There are lots of different ways to go about keeping hackers out of the web application you're developing. Some of these become standard (md5 is a function in most builds of PHP) while others require a bit more knowledge (e.g. using hash("sha256", $password) instead of sha1($password) for password hashes).

Often times, implementing security carries the risk of making code messy and unreadable. As a result, I often refactor code I had written for security purposes into functions in my own special library. Here's a small selection of some of the more versatile functions.

All of these functions have been tested with PHP 5.2.17 and 5.3.5; although most of these should work on earlier versions.

AES-256 and TwoFish shorthand functions for plaintext encryption (requires mcrypt):
PHP Code:
function AES256_Encrypt($sValue$sSecretKey)
{
  return 
trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256$sSecretKey$sValueMCRYPT_MODE_ECBmcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256MCRYPT_MODE_ECB), MCRYPT_RAND))));
}    
function 
AES256_Decrypt($sValue$sSecretKey)
{
  return 
trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256$sSecretKeybase64_decode($sValue), MCRYPT_MODE_ECBmcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
function 
TwoFish_Encrypt($sValue$sSecretKey) {
  return 
trim(base64_encode(mcrypt_encrypt(MCRYPT_TWOFISH$sSecretKey$sValueMCRYPT_MODE_ECBmcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_TWOFISHMCRYPT_MODE_ECB), MCRYPT_RAND))));
}
function 
TwoFish_Decrypt($sValue$sSecretKey) {
  return 
trim(mcrypt_decrypt(MCRYPT_TWOFISH$sSecretKeybase64_decode($sValue), MCRYPT_MODE_ECBmcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_TWOFISHMCRYPT_MODE_ECB), MCRYPT_RAND)));

NoInject: For stopping SQL injections the lazy way.
PHP Code:
function noinject($query$mode="mysql") {
  if(
get_magic_quotes_runtime()) $query stripslashes($query);
  if(
$mode == "sqlite") {
    return 
sqlite_escape_string($query);
  } else {
      return 
mysql_real_escape_string($query);
  }

Force ASCII -- Just a shorthand for stripping non-ASCII characters in case your specific application uses non-ASCII characters for delimiting data (for example):
PHP Code:
function forceASCII($in) {
  return 
preg_replace('/[^(\x20-\x7F)]*/',''$in);

Whether you're new to PHP or a refined coder, you should find use for these functions if you don't already have your own.
RiptideTempora is offline   Reply With Quote
Sponsored Links
Old 12-09-2011, 01:38 AM   #2 (permalink)
Junior Member
 
Join Date: Nov 2011
Posts: 9
Smile Re: A Selection Riptide Tempora's Security Library


Hi... Friends...!!!

Thanks for your valuable post...!! I like your post.


Weblogicx | Logicx for Business
Hostlogicx | Simply Hosting
hanmant is offline   Reply With Quote
Reply

Tags
encryption , security , sqli

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 05:03 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting