473,889 Members | 1,656 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
19 18645
> True, but the original discussion, I believe, was on storing user
passwords etc... for which md5 is the preferred method...


I thought the original question was what to use for storing credit cards,
for which you want a decryptable method. (A public/private key method
would be even better for credit card data IMHO, but I don't think pgcrypto
includes one.)
--
Mike Nolan

---------------------------(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 #11
sc***********@i hs.com ("scott.marlowe ") wrote:
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...


No, the original discussion was about encrypting fields in the
database, so MD5 doesn't cut it.

Actually, for the purpose being pointed at, I would actually suggest
that the Gentle User consider preferring that the database DOESN'T
directly support encryption, because if it did, it would be tempting
to pass encryption keys to the database, thereby COMPROMISING the
security of the system.

After all, suppose the database supports stored procedures of the
form:

encrypt(key, field)
and
decrypt(key, field)

Then an unscrupulous sysadmin type could replace them with alternative
stored procedures that add in a couple of inserts...

insert into nefarious_schem a.keep_keys (id, key) values (nextval('my_ke ying'), key);
insert into nefarious_schem a.keep_field (id, field) values (currval('my_ke ying'), field);

The data can only remain truly secure in the database if encryption
and decryption don't even take place there.

It is all well and nifty to throw encryption tools into the database,
but this example quite clearly demonstrates that this is not a recipe
for _improving_ security of the system...
--
"cbbrowne","@", "ntlug.org"
http://www3.sympatico.ca/cbbrowne/crypto.html
"Computers double in speed every 18 months or so, so any "exponentia l
time" problem can be solved in linear time by waiting the requisite
number of months for the problem to become solvable in one month and
then starting the computation." -- pr***@Sunburn.S tanford.EDU
Nov 23 '05 #12
I think, that all is about key management. You can store your data with
strong RSA encryption. On server you will have only public key and on
client PC private key.

it's not so easy to use, but it's more secure than symmetrical cipher.

miso

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #13
On Mon, 12 Apr 2004, Christopher Browne wrote:
sc***********@i hs.com ("scott.marlowe ") wrote:
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...


No, the original discussion was about encrypting fields in the
database, so MD5 doesn't cut it.


OK, thanks. I think I got my threads cross-wired.
Actually, for the purpose being pointed at, I would actually suggest
that the Gentle User consider preferring that the database DOESN'T
directly support encryption, because if it did, it would be tempting
to pass encryption keys to the database, thereby COMPROMISING the
security of the system.


I agree completely. There's a new italian law that says that everything
in a database that's personal data has to be encrypted, and there was
another discussion on that. Did you see that one go by? Seems the law
isn't real clear on where encryption / decryption or key holding should
take place.
---------------------------(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 #14
On Sun, 11 Apr 2004, Jerry McBride wrote:
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....


let's see:

su -
cd /usr/local/src/postgresql-7.4.2
cd contrib/pgcrypto
make
make install

Total time taken: <30 seconds.

If that's a make or break deal for you on a database I'd hate to go car
buying with you.
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #15
does any one know how to get an md5()-like hash function using pgcrypto
for postgresql 7.3 ? without upgrading to 7.4

Thanks for any input.

Dias

scott.marlowe wrote:
On Sun, 11 Apr 2004, Jerry McBride wrote:

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....

let's see:

su -
cd /usr/local/src/postgresql-7.4.2
cd contrib/pgcrypto
make
make install

Total time taken: <30 seconds.

If that's a make or break deal for you on a database I'd hate to go car
buying with you.
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #16
I think that's what digest does. It doesn't appear to install in 7.4
since 7.4 has the md5 function. I don't have a 7.3 box to test it on
though...

On Tue, 11 May 2004, Dias Bantekas wrote:
does any one know how to get an md5()-like hash function using pgcrypto
for postgresql 7.3 ? without upgrading to 7.4

Thanks for any input.

Dias

scott.marlowe wrote:
On Sun, 11 Apr 2004, Jerry McBride wrote:

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....

let's see:

su -
cd /usr/local/src/postgresql-7.4.2
cd contrib/pgcrypto
make
make install

Total time taken: <30 seconds.

If that's a make or break deal for you on a database I'd hate to go car
buying with you.
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #17
Dias Bantekas wrote:
does any one know how to get an md5()-like hash function using pgcrypto
for postgresql 7.3 ? without upgrading to 7.4

Thanks for any input.


SELECT encode(digest(v _password, 'md5'), 'hex');

hlk
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #18
Dias Bantekas wrote:
does any one know how to get an md5()-like hash function using
pgcrypto for postgresql 7.3 ? without upgrading to 7.4

Thanks for any input.


SELECT encode(digest(v _password, 'md5'), 'hex');


BTW,

/usr/share/pgsql/contrib/pgcrypto.sql

is the script that defines the encode and digest functions.

--Berend Tober


---------------------------(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 #19
bt****@computer .org wrote:
Dias Bantekas wrote:

does any one know how to get an md5()-like hash function using
pgcrypto for postgresql 7.3 ? without upgrading to 7.4

Thanks for any input.


SELECT encode(digest(v _password, 'md5'), 'hex');

BTW,

/usr/share/pgsql/contrib/pgcrypto.sql

is the script that defines the encode and digest functions.

--Berend Tober


thanks hlk, that's exactly what I was looking for.
Now I can create a md5() function and do my job!

encode is a native PG string function, it is not defined in pgcrypto.
Dias
---------------------------(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 #20

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

Similar topics

1
12520
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
1559
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
1689
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
3383
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
1993
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
4407
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
9969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9810
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,...
0
11203
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
10794
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
10896
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,...
1
7999
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
5830
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4650
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 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.