473,854 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data Encryption in PostgreSQL, and a Tutorial.

Has anyone created something like that for Postgresql? It would be
really handy to encrypt credit card numbers and other information so
it stays secure.

If no one has created anything such as this, I am going to code up
something quite soon, but if it already exists, there is no need for
me to reinvent the wheel, so speak up! It is a law in places such as
the EU that many types of data must be encrypted if the database is
compromised.

I will put up my solution in a few days if one does not exist. But
before I do that, I want to give a quick tutorial on how to create a
file that will create tables, views and other such essentials. Most
people who use PostgreSQL just type in the commands in PostgreSQL, but
that is not as easily portable or backed up as what I'm about to show
you!

1. open vi with a file.
2. Comments can be made as long as you add to slashes before the
line:
--this is a comment.
3. Next just type in the SQL commands you want!
4. after you are done, save the file.
5. then just do this to create the database you made in the file:
psql database_name < my_vi_file
6.That is it!

Here is a very simple sample of a file:

--This is a sample file. Use at your own risk. No Warranties
--Written by Mike Cox, author of the *nix "hm" command.

create table first(
MYNUMBER INTEGER);

create VIEW myview AS
select * from first;

--Ok this is the end. As you can see it is very simple and portable.
--Try it out. Here's how: psql your_database < this_file
Nov 23 '05 #1
19 18641
Mike Cox wrote:
Has anyone created something like that for Postgresql? It would be
really handy to encrypt credit card numbers and other information so
it stays secure.

If no one has created anything such as this, I am going to code up
something quite soon, but if it already exists, there is no need for
me to reinvent the wheel, so speak up! It is a law in places such as
the EU that many types of data must be encrypted if the database is
compromised.

I will put up my solution in a few days if one does not exist. But
before I do that, I want to give a quick tutorial on how to create a
file that will create tables, views and other such essentials. Most
people who use PostgreSQL just type in the commands in PostgreSQL, but
that is not as easily portable or backed up as what I'm about to show
you!

1. open vi with a file.
2. Comments can be made as long as you add to slashes before the
line:
--this is a comment.
3. Next just type in the SQL commands you want!
4. after you are done, save the file.
5. then just do this to create the database you made in the file:
psql database_name < my_vi_file
6.That is it!

Here is a very simple sample of a file:

--This is a sample file. Use at your own risk. No Warranties
--Written by Mike Cox, author of the *nix "hm" command.

create table first(
MYNUMBER INTEGER);

create VIEW myview AS
select * from first;

--Ok this is the end. As you can see it is very simple and portable.
--Try it out. Here's how: psql your_database < this_file


MySQL has encryption and decryption functions built in, doesn't Postgresql?

Todd

Nov 23 '05 #2
Hello,

Actually I would use psql with the \e option. This would allow you to do
what you suggest but also
allow you to stay within psql while you debug your statements. Then when
you are all done and
you have used the appropriate amount of COMMENT ON statements, you can
just do a pg_dump -s
and you are good to go.

Sincerely,

Joshua D. Drake
Mike Cox wrote:
Has anyone created something like that for Postgresql? It would be
really handy to encrypt credit card numbers and other information so
it stays secure.

If no one has created anything such as this, I am going to code up
something quite soon, but if it already exists, there is no need for
me to reinvent the wheel, so speak up! It is a law in places such as
the EU that many types of data must be encrypted if the database is
compromised.

I will put up my solution in a few days if one does not exist. But
before I do that, I want to give a quick tutorial on how to create a
file that will create tables, views and other such essentials. Most
people who use PostgreSQL just type in the commands in PostgreSQL, but
that is not as easily portable or backed up as what I'm about to show
you!

1. open vi with a file.
2. Comments can be made as long as you add to slashes before the
line:
--this is a comment.
3. Next just type in the SQL commands you want!
4. after you are done, save the file.
5. then just do this to create the database you made in the file:
psql database_name < my_vi_file
6.That is it!

Here is a very simple sample of a file:

--This is a sample file. Use at your own risk. No Warranties
--Written by Mike Cox, author of the *nix "hm" command.

create table first(
MYNUMBER INTEGER);

create VIEW myview AS
select * from first;

--Ok this is the end. As you can see it is very simple and portable.
--Try it out. Here's how: psql your_database < this_file

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

--
Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC
Postgresql support, programming shared hosting and dedicated hosting.
+1-503-667-4564 - jd@commandpromp t.com - http://www.commandprompt.com
PostgreSQL Replicator -- production quality replication for PostgreSQL
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #3
In an attempt to throw the authorities off his trail, "T. Relyea" <no****@nospam. com> transmitted:
MySQL has encryption and decryption functions built in, doesn't Postgresql?


But of course.

See the "pgcrypto" contrib module in the source tree.

It is not typically compiled into what gets distributed with the
typical Linux/BSD distribution because of the library dependencies
that it forces in, as well as because the legalities surrounding the
distribution of cryptographic software vary from country to country,
making it potentially legally unsafe to ubiquitously include it.
--
let name="cbbrowne" and tld="acm.org" in name ^ "@" ^ tld;;
http://www.ntlug.org/~cbbrowne/spreadsheets.html
"If God meant us to be vegetarians why'd He make cows out of meat?"
-- seen on a bumper sticker
Nov 23 '05 #4
mlw
Mike Cox wrote:
Has anyone created something like that for Postgresql? It would be
really handy to encrypt credit card numbers and other information so
it stays secure.


Do you want to require a key to extract data or do you want to create an
encrypted data stream?

If you want to create an encrypted data element within the database that
requires a key, you would need to create a few functions, something like:

login(username varchar, passwd varchar, key cryptkey)
logout(username varchar)

You would also need to create a table of keys, something like this:

create table (username varchar, key cryptkey);

Lastly, one more set of functions for the various data types supported:

varchar decrypt(datum varchar)
int decrypt(datum int)

and

varchar crypt(..)
int crypt(...)
It is totally doable, and I'm not sure there is one out there. The only real
way to do it is public/private key encryption.

Nov 23 '05 #5
> Has anyone created something like that for Postgresql? It would be
really handy to encrypt credit card numbers and other information so
it stays secure.


Is there some reason you can't use contrib/pgcrypto? I use it
for storing passwords in an MD5 encryption and credit card data using
encrypt/decrypt, because I don't think it supports public/private
key encryption.
--
Mike Nolan

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #6
T. Relyea wrote:
Mike Cox wrote:
Has anyone created something like that for Postgresql? It would be
really handy to encrypt credit card numbers and other information so
it stays secure.

If no one has created anything such as this, I am going to code up
something quite soon, but if it already exists, there is no need for
me to reinvent the wheel, so speak up! It is a law in places such as
the EU that many types of data must be encrypted if the database is
compromised.

I will put up my solution in a few days if one does not exist. But
before I do that, I want to give a quick tutorial on how to create a
file that will create tables, views and other such essentials. Most
people who use PostgreSQL just type in the commands in PostgreSQL, but
that is not as easily portable or backed up as what I'm about to show
you!

1. open vi with a file.
2. Comments can be made as long as you add to slashes before the
line:
--this is a comment.
3. Next just type in the SQL commands you want!
4. after you are done, save the file.
5. then just do this to create the database you made in the file:
psql database_name < my_vi_file
6.That is it!

Here is a very simple sample of a file:

--This is a sample file. Use at your own risk. No Warranties
--Written by Mike Cox, author of the *nix "hm" command.

create table first(
MYNUMBER INTEGER);

create VIEW myview AS
select * from first;

--Ok this is the end. As you can see it is very simple and portable.
--Try it out. Here's how: psql your_database < this_file


MySQL has encryption and decryption functions built in, doesn't
Postgresql?

Todd


Obviously not... that's why we don't use it at work....

--

*************** *************** *************** *************** *************** ***
Registered Linux User Number 185956
http://groups.google.com/groups?hl=e...ff&group=linux
Join me in chat at #linux-users on irc.freenode.ne t
This email account no longers accepts attachments or messages containing
html.
12:26pm up 35 days, 13:39, 2 users, load average: 2.51, 2.56, 2.58
Nov 23 '05 #7
On Fri, 9 Apr 2004, Christopher Browne wrote:
In an attempt to throw the authorities off his trail, "T. Relyea" <no****@nospam. com> transmitted:
MySQL has encryption and decryption functions built in, doesn't Postgresql?


But of course.

See the "pgcrypto" contrib module in the source tree.

It is not typically compiled into what gets distributed with the
typical Linux/BSD distribution because of the library dependencies
that it forces in, as well as because the legalities surrounding the
distribution of cryptographic software vary from country to country,
making it potentially legally unsafe to ubiquitously include it.


I thought md5() was a built-in nowadays...
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #8
"scott.marl owe" <sc***********@ ihs.com> writes:
On Fri, 9 Apr 2004, Christopher Browne wrote:
See the "pgcrypto" contrib module in the source tree.

It is not typically compiled into what gets distributed with the
typical Linux/BSD distribution because of the library dependencies
that it forces in, as well as because the legalities surrounding the
distribution of cryptographic software vary from country to country,
making it potentially legally unsafe to ubiquitously include it.
I thought md5() was a built-in nowadays...


Yeah, it is, but md5 is not considered cryptography because it is not
reversible (you can't decrypt to get back what you put in). As such
it's not restricted under US munitions law, nor anyone else's that
I've heard of.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #9
On Mon, 12 Apr 2004, Tom Lane wrote:
"scott.marl owe" <sc***********@ ihs.com> writes:
On Fri, 9 Apr 2004, Christopher Browne wrote:
See the "pgcrypto" contrib module in the source tree.

It is not typically compiled into what gets distributed with the
typical Linux/BSD distribution because of the library dependencies
that it forces in, as well as because the legalities surrounding the
distribution of cryptographic software vary from country to country,
making it potentially legally unsafe to ubiquitously include it.

I thought md5() was a built-in nowadays...


Yeah, it is, but md5 is not considered cryptography because it is not
reversible (you can't decrypt to get back what you put in). As such
it's not restricted under US munitions law, nor anyone else's that
I've heard of.


True, but the original discussion, I believe, was on storing user
passwords etc... for which md5 is the preferred method...
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12519
by: Ronald Evers | last post by:
Hey all, I want to store passwords in a postgresql database. Currently I use the MD5Password class below and I've been developing on windows. I ran into problems when running my application on linux. Linux and Windows, with same JDK's (1.5.0), create different encrypted password strings. So when testing a password created on one platform on the other, it will fail :(
3
1557
by: Steve | last post by:
Hi, Can someone please point me out to some module/library for using PostgreSQL from python? Perhaps a tutorial as wel? Thanks! Steve
3
5022
by: Molly Gibson | last post by:
Hi all, I have recently installed Apache/1.3.28 + mod_auth_pgsql-0.9.12 (http://www.giuseppetanzilli.it/mod_auth_pgsql/) The only way I have been able to get it to successfully authenticate against my postgres (7.3.4) database is to turn Auth_PG_encrypted off & have encryption turned off in postgresql.conf. I am really uncomfortable with the idea of having unencrypted user
2
9773
by: SmoothJazz | last post by:
Hi All! I am wanting to setup/run PostgreSQL on my server (a SuSE Linux 9.2 distro) but I'm not quite sure which way to go. I have a few books on PostgreSQL but they don't seem to match the way SuSE has installed it. The books explain how to install/make/etc. and then how to setup a "cluster". The directory structure differs alot from the SuSE install.
6
1686
by: SR | last post by:
As a starter project for learning Python/PostgreSQL, I am building a Books database that stores information on the books on my bookshelf. Say I have three tables. Table "books" contains rows for book_id, title, subtitle, ISBN. Table "authors" contains rows for author_id, author surname, author first names, biographical notes.
0
3382
by: Hannibal111111 | last post by:
I found this code on a site for doing string encryption/decryption. The string will encrypt fine, but I get this error when I try to decrypt. Any idea why? I posted the code below. The error actually points to this line of code in byte decrypt function: cs.FlushFinalBlock(); public static byte encrypt(byte clearData, byte Key, byte IV)
4
1992
by: Alfred | last post by:
The PHP web app that I'm building uses PostgreSQL. Of course it won't work right off the bat, so my web app is going to have to detect that it has never been configured with a database and have to instruct the sysop on what to do. What are developers in the PHP industry doing with their installers to ensure everything with PostgreSQL is going to work out right? In particular I'm going to want the web app to have a local database (by...
0
1634
by: Rico | last post by:
Hello, Does anyone have a good link for a tutorial / best practices for using encryption in SQL Server 2005? Thanks! Rick
3
4404
by: Sin Jeong-hun | last post by:
It seems like the Protect() uses the Windows accout information to encrypt data. If I know the user name and the password, can I decrypt it on another PC? If it is not, how about the exported key? On Windows Vista, if file encryption is used, Windows suggests to back up the key. If I import the key on another PC, then can I decrypt a data protected by the Protect() method? Or it is impossible by any means?
0
11044
Oralloy
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...
0
10692
jinu1996
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...
1
10767
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,...
0
10375
tracyyun
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...
0
9526
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7927
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7084
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();...
1
4567
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
2
4168
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.