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


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
goodkAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Bhavesh ShahConnect With a Mentor Lead AnalysistCommented:
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
 
Bhavesh ShahLead AnalysistCommented:
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
 
Ryan McCauleyConnect With a Mentor Data and Analytics ManagerCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
OP_ZaharinConnect With a Mentor Commented:
-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
 
goodkAuthor Commented:
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
 
Ryan McCauleyData and Analytics ManagerCommented:
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
 
OP_ZaharinCommented:
ryan have a point there.
you should use the hash or encryption feature made available by the database.
0
 
goodkAuthor Commented:

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
 
Ryan McCauleyConnect With a Mentor Data and Analytics ManagerCommented:
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
 
goodkAuthor Commented:
thanks
0
All Courses

From novice to tech pro — start learning today.