Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

store procedure to save secure information like dob, ssnumber, etc..

Posted on 2011-03-14
10
Medium Priority
?
573 Views
Last Modified: 2012-05-11

Is there a way to store some important information so when I send the password parameter it returns the stored character string?

I am using
Microsoft SQL Server Management Studio                                    10.0.2531.0
ms sql express 8
0
Comment
Question by:goodk
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 35135410
Hi,

There not any option by passing password, you got that information on specific column.

What you can do is,

1. You can create one database user to control specific table.
   Only that user having access to table.

2. you can use encryption for hiding specific column value.

If you need more info on any one, let me know.


- Bhavesh
0
 
LVL 28

Assisted Solution

by:Ryan McCauley
Ryan McCauley earned 400 total points
ID: 35135422
The most secure way to store these things is so normal users don't have SELECT access on the table and only a stored procedure can access it - that way, when the user calls the stored procedure with a key of some kind (like you're suggesting), and then the stored procedure returns the details for that record. DBA-level users (or at least one) would still need to be able to view the raw data in the table - though you can encrypt it if you'd like - since somebody will need to create the structure and troubleshoot any issues that arise.

You'd have to ensure a couple of things:

Your application doesn't have DBO rights on that database, and can't either view the data or grant permissions on the data
The key you're using (to call your stored procedure and pull a certain row) has to be long enough to make the possibility of guessing it highly unlikely
This goes along with the previous point, but the key CANNOT BE AN INCREMENTING INT. I've seen this before and you could view other peoples' data just by incrementing your key value - very bad

What you're describing can be done, and it can be done safely, but you'll have to ensure that you protect your data, since all the security in the world doesn't matter if there's a backdoor in to view everything and the application can gain access to it.
0
 
LVL 23

Assisted Solution

by:OP_Zaharin
OP_Zaharin earned 200 total points
ID: 35135457
-here is a sample on sql server encryption on a column:
http://www.sqlsolutions.com/articles/articles/Encrypted_Columns_and_SQL_Server_Performance.htm

-here is another sample that might be useful to use hash on password field: http://blogs.msdn.com/b/sqlcat/archive/2005/09/16/469257.aspx
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:goodk
ID: 35138713
thanks, guys -

So is it not possible to create an encrytion key and corresponding encryptic text?  I wanted to save incription key in column and encrypted text in the other column.  Is this not possible? if yes, how?

thanks
0
 
LVL 28

Expert Comment

by:Ryan McCauley
ID: 35138940
Sure, it's possible to do this, but why encrypt it at all if you're just going to store the key along with the data? Anybody who compromises the data will have access to the key as well, so it defeats the purpose.
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 35139269
ryan have a point there.
you should use the hash or encryption feature made available by the database.
0
 

Author Comment

by:goodk
ID: 35139382

thanks,

you are absolutely right that if someone gets hold of the data they have all the information.

ok, correct me on what I am thinking, if it is right?

I was going to use the password with the encrytion key as an added key.

I already know how to write a stored procedure to secure and verify the password.  I, however, do not know how to encrypt some thing and the get the original back.  That is what I am asking. thanks

0
 
LVL 28

Assisted Solution

by:Ryan McCauley
Ryan McCauley earned 400 total points
ID: 35139454
Here's the Microsoft walk-through for using a server certificate to encrypt a column's data:

http://msdn.microsoft.com/en-us/library/ms179331.aspx

This is the safest way to do it, since you're letting SQL Server protect your certificate (decryption key). If you prefer to handle the password and decryption yourself, SQL also supports password-based symmetric en/decryption:

http://dotnetslackers.com/articles/sql/IntroductionToSQLServerEncryptionAndSymmetricKeyEncryptionTutorial.aspx

The second one is more what you're asking for, but I'd lean you towards the first since it lets the server handle more of the details, and I'm always a fan of not re-rolling what's already been build for me :)
0
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 1400 total points
ID: 35144125
Hi,

Checkout this function too which is I'm using.

We are using "EncryptByPassphrase" for encryption.

For more info on

http://technet.microsoft.com/en-us/library/ms190357.aspx


- Bhavesh
CREATE Function [dbo].[Encrypt] (@Key VARCHAR(50), @Password VARCHAR(150)) Returns VARBINARY(MAX)
As
	
Begin

	DECLARE @EncryptedPassword VARBINARY(MAX)

	SET @EncryptedPassword = EncryptByPassphrase(@Key, @Password)

	Return @EncryptedPassword
End

Open in new window

DECLARE @Key VarChar(50)
Declare @Password Varchar(50)
Declare @EncryptedPassword Varchar(50)


SET @Key = 'bj12@*$%98rs'
SET @Password = 'patience'
SET @EncryptedPassword = DBO.encrypt(@Key,@Password)

SELECT @Password OriginalPassword,@EncryptedPassword 'EncryptedPassword',DBO.Decrypt(@Key,@EncryptedPassword)DecryptedPassword

Open in new window

CREATE Function [dbo].[Decrypt] (@Key VARCHAR(50), @EncryptedPassword varchar(MAX)) Returns VARCHAR(150)
As
	
Begin

	DECLARE @DecryptedPassword VARCHAR(150)

	SET @DecryptedPassword = CAST(DecryptByPassphrase(@Key, @EncryptedPassword) AS VARCHAR(MAX))
	
	Return @DecryptedPassword
End

Open in new window

0
 

Author Closing Comment

by:goodk
ID: 35226609
thanks
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, we’ll look at how to deploy ProxySQL.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question