Of course, one could always use other kinds of
encryption/encoding/obfuscation techniques such as XOR complement, but
this example provides an extremely secure version using methods like
Blowfish, MD5, DES, etc.
This took me about 4 hours to figure out and perfect, but the two
functions below will work with PHP on many versions of Linux. I have
RedHat 9, in this case. I designed this to use a pretty small
compression and encryption style, yet work just fine as far as storing
in a cookie.
I'm using Blowfish here, but you can switch the "-bf" to other
encryption types. For those of you with Linux, do a "man openssl" to
see the others that are available.
The routine isn't bad for a 15 user business app on a 2.4Ghz Pentium.
However, you'll find it's somewhat slow for larger-scale operations,
unfortunately, because you have to write 2 files for each function. If
someone knows how to use openssl without files, I'd be interested to
see your example.
function Encrypt($val, $pass) {
$val = str_replace("'" , "#%$", $val);
$file = tempnam('','php-encrypt-');
exec("echo -E '$val' > $file.dec");
exec("openssl enc -a -bf -in $file.dec -out $file.enc -e -pass
pass:$pass");
$myfile = file("$file.enc ");
exec("rm $file");
exec("rm $file.dec");
exec("rm $file.enc");
while (list($line_num , $line) = each($myfile)) {
$result .= $line;
}
$result = base64_encode($ result);
$result = urlencode($resu lt);
return $result;
}
function Decrypt($val, $pass) {
$val = urldecode($val) ;
$val = base64_decode($ val);
$file = tempnam('','php-decrypt-');
exec("echo -E '$val' > $file.enc");
exec("openssl enc -a -bf -in $file.enc -out $file.dec -d -pass
pass:$pass");
$myfile = file("$file.dec ");
exec("rm $file");
exec("rm $file.enc");
exec("rm $file.dec");
while (list($line_num , $line) = each($myfile)) {
$result .= $line;
}
$result = substr($result, 0, strlen($result)-1);
$result = str_replace("#% $", "'", $result);
return $result;
}
Here's a sample of how big the encrypted string can be when I used the
password "wow":
6 chars = 44 chars
20 chars = 76 chars
50 chars = 134 chars
100 chars = 224 chars
Here's a sample encrypted string:
VTJGc2RHVmtYMSt 4azRFdjN2QXlzVk JZRFBMMTdHNmNlQ WdGZFF0ZmlkNS9C QndPOGtIOGV3PT0 K 0 3259 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Drazen Gemic |
last post by:
Is there a way to extend PHP features, like adding new database
connectivity module, java interoperability etc. without recompiling PHP ?
I need a UNIX/Linux solution, something like dropping .so file in
certain directory.
I am not a hobbist, and I do not have root priviledge at my customers site.
My customers are not always capable to recompile PHP themselves, and it
causes me problems.
I am considering moving to Java/JSP/Velocity...
|
by: Ben |
last post by:
Hi all,
I used PHP installer binary to install PHP. Then I installed MySQL.
Now how do I reconfigure PHP to connect to MySQL? In PHP installer, it
does not provide any options for mysql support. Is it possible to do
it with PHP binary installer or do I need to reinstall PHP from source
code?
Hope someone can help me!
Thanx
|
by: Blake T. Garretson |
last post by:
I want to save some sensitive data (passwords, PIN numbers, etc.) to
disk in a secure manner in one of my programs. What is the
easiest/best way to accomplish strong file encryption in Python? Any
modern block cipher will do: AES, Blowfish, etc. I'm not looking for
public key stuff; I just want to provide a pass-phrase.
I found a few modules out there, but they seem to be all but abandoned.
Most seem to have died several years ago. ...
|
by: Charlie |
last post by:
Hi:
My host will not allow me use a trusted connection or make registry setting,
so I'm stuck trying find a way to hide connection string which will be
stored in web.config file. If I encrypt string externally, can it be used
in it's encrypted form to connect to SQL Server? If I decrypt back to
string for use in connection string during runtime, I have to supply a key.
If I do that, hacker could use key to break encryption. How do I...
|
by: Chris Snyder |
last post by:
Hello all. I have a problem that is probably failry easy to solve, but
I don't know where to look. (Or, really, what to look for.)
My customer has a tool (written in .NET) that encrypts strings. They
require us to use the tool to encrypt the connection strings to the
"real" database. We have had no problem with that.
However, they also want to use SQL Server to manage session state, and
would really like the ConnectionString to the...
| |
by: WebMatrix |
last post by:
Hello,
I have developed a web application that connects to 2 different database
servers. The connection strings with db username + password are stored in
web.config file.
After a code review, one developer suggested that it's a security flaw;
therefore connection strings should be kept somewhere else or encrypted.
My argument is that web.config file is protected by IIS and Windows security
which is the case. And another argument is that...
|
by: JJ |
last post by:
I need to encrypt credit card # and store that in a database (and be able to
decrypt it). Any codes that use strong encyption algorithm like AES 256 on
the web that I can copy and paste?
Thanks
|
by: robert maas, see http://tinyurl.com/uh3t |
last post by:
I'm working on examples of programming in several languages, all
(except PHP) running under CGI so that I can show both the source
files and the actually running of the examples online. The first
set of examples, after decoding the HTML FORM contents, merely
verifies the text within a field to make sure it is a valid
representation of an integer, without any junk thrown in, i.e. it
must satisfy the regular expression: ^ *?+ *$
If the...
|
by: j1mb0jay |
last post by:
I have created some simple string encryption in C# to be able to store
passwords in a database without them being stored in plain text.
I have attached a encrypted passage from a book I like. Please let me
know if it is really simple to crack.
Regards j1mb0jay
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |