If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Hashing a char column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-20-11, 12:11
merik merik is offline
Registered User
 
Join Date: Apr 2011
Posts: 32
Hashing a char column

I want to do something like

Code:
SELECT MD5(SSN), FIELD1, FIELD2 FROM TABLE
So I the actual SSN's are not shown on my screen, but the MD5 hashes are shown. In other words, I want the SSN to be hashed.

How can I do this in DB2? If there is no built in function, how can I create one?

Please note that I don't have many permissions, and I prefer something I can do on my own. However, if it's really impossible, I can ask the DB admin to enable features.
Reply With Quote
  #2 (permalink)  
Old 04-20-11, 12:51
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
If you didn't stick to MD5 algorithm, you can use ENCRYPT built-in function.

IBM DB2 9.7 for Linux, UNIX, and Windows
Version 9 Release 7
SQL Reference, Volume 1

Quote:
Notes
v Encryption algorithm: The internal encryption algorithm is RC2 block cipher
with padding; the 128-bit secret key is derived from the password using an MD5
message digest.
Reply With Quote
  #3 (permalink)  
Old 04-20-11, 13:22
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Reply With Quote
  #4 (permalink)  
Old 04-21-11, 14:29
merik merik is offline
Registered User
 
Join Date: Apr 2011
Posts: 32
Quote:
Originally Posted by tonkuma View Post
If you didn't stick to MD5 algorithm, you can use ENCRYPT built-in function.

IBM DB2 9.7 for Linux, UNIX, and Windows
Version 9 Release 7
SQL Reference, Volume 1
Thank you! It worked after I executed the SET ENCRYPTION PASSWORD command.

Quote:
Originally Posted by n_i View Post
I found that when I was searching the forum (before asking this question) but I don't have create function permission
Reply With Quote
  #5 (permalink)  
Old 04-22-11, 13:44
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Beware that hashing (like md5) and encrypting are not similar things!

In order to encrypt, you need a password, which will allow you to decrypt later on.
This means that someone in the possession of the password (e.g., the DBA, or the program that does the encryption) can recover the original SSN.

Hashing, on the other hand, is a one-way function: no password is needed to "mangle" the data, but there exists no "unmangle" function, so there is a guarantee that no-one will be able to recover the SSN from its hashed value.
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #6 (permalink)  
Old 04-22-11, 14:19
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Frankly, I don't see any reason for displaying hashed or encrypted SSNs. If you don't want to show them, don't show them. I mean, at all. Why showing seemingly random characters instead?
Reply With Quote
Reply

Tags
hash, md5

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On