Mike108
Mike108

Reputation: 2137

Is there an encryption method for a column with a data type of int?

The scenario is that I want to encrypt finance numbers in a column with a data type of int in a sql server table. It is a big app so it is difficult to change the table column data type from int to any other data type.

I'm using sql server 2005 and asp.net C#.

Is there a two-way encryption method for a column with a data type of int?

Could I use a user-defined-function in sql server 2005 or a possibly a C# method?

Upvotes: 5

Views: 2117

Answers (5)

Accipitridae
Accipitridae

Reputation: 3194

You might want to look at format preserving encryption.

Upvotes: -1

Jens
Jens

Reputation: 25563

Well, every injective, surjective function from int to int can be used as a way to "encode" an integer.

You could build such a function by creating a random array with 65536 items with no duplicate entries und using f(i) = a[i]. To "decode" your int you simply create another array with b[i] = x | a[x] = i.

As the others have mentioned, this may not be what you REALLY want to do. =)

Edit: Check out Jim Dennis' comment!

Upvotes: 0

paxdiablo
paxdiablo

Reputation: 881103

I'm sorry but I simply can't see the rationale for encrypting numbers in a database. If you want to protect the data from prying eyes, surely SQL Server has security built into it, yes?

In that case, protect the database with its standard security. If not, get a better DBMS (though I'd be surprised if this were necessary).

If you have bits of information from that table that you want to make available (like some columns but not others), use a view, or a trigger to update another table (less secured), or a periodic transfer to that table.

Upvotes: 4

Spencer Ruport
Spencer Ruport

Reputation: 35107

There are a few two way encryption schemes available in .Net.

Simple insecure two-way "obfuscation" for C#

You can either convert the integer to it's byte array equivalent or convert it to a base-64 string and encrypt that.

Upvotes: 0

leppie
leppie

Reputation: 117220

XOR?

:)

Hmm, need more text...

 

Upvotes: 1

Related Questions