473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Best Practice for storing keys

I am trying to find the best procedure for storing keys used for encryption.

This would also be a question for the connection string to the database. At
the moment, this is kept in the web.info file.

This seems to be norm from all the books on building your Web Apps. Isn't
this a problem as the web.info is cleartext? I would suppose that having
keys (which you would to store/encrypt and get/decrypt from your database)
in this manner would be dangerous.

I am trying to find out how others deal with this. Also, I would need the
same information for my Apps on the same machine.

Thanks,

Tom
Jan 3 '07 #1
10 2031
Han
Hello

Sounds like RSA encription.

http://msdn2.microsoft.com/en-us/library/2w117ede.aspx

Note there is one mistake in the example.

<configProtectedData>
<providers>
<add name="MyProvider"
type="System.Configuration.RsaProtectedConfigurati onProvider,
System.Configuration, Version=2.0. 0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
processorArchitecture=MSIL"
keyContainerName="MyKeys"
useMachineContainer="true" />
</providers>
</configProtectedData>

2.0. 0.0 should be 2.0.0.0.

If you are successful encripting some part of your configuration, the key is
secured with NTFS Access Control Lists. Good luck.

"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I am trying to find the best procedure for storing keys used for
encryption.

This would also be a question for the connection string to the database.
At
the moment, this is kept in the web.info file.

This seems to be norm from all the books on building your Web Apps. Isn't
this a problem as the web.info is cleartext? I would suppose that having
keys (which you would to store/encrypt and get/decrypt from your database)
in this manner would be dangerous.

I am trying to find out how others deal with this. Also, I would need the
same information for my Apps on the same machine.

Thanks,

Tom


Jan 3 '07 #2
"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I am trying to find the best procedure for storing keys used for
encryption.
Generally speaking, don't store them at all - devise a mechanism for
generating the same key whenever you need it...
http://msdn.microsoft.com/msdnmag/is...efault.aspx#S9
This seems to be norm from all the books on building your Web Apps. Isn't
this a problem as the web.info is cleartext? I would suppose that having
keys (which you would to store/encrypt and get/decrypt from your database)
in this manner would be dangerous.
I think there's a lot of FUD (fear, uncertainty and doubt) surrounding
this...

Firstly, ask yourself who are you hiding this key from...? Your
colleagues...? Your boss...? The office cleaner...? If you are worried about
whether your fellow employees are trustworthy or not, then you have a much
bigger problem then key encryption...

Secondly, is your website's security so lax that your web.config is visible
to the outside world...? Again, if that is the case, then you have a much
more fundamental problem than key encryption...

Are you perhaps worried about "professional" hackers...? Again, if a hacker
is clever enough to bypass all your security protection and is able to gain
access to your webserver, it probably won't matter much whether your key is
encrypted or not - they'll crack it...
I am trying to find out how others deal with this. Also, I would need the
same information for my Apps on the same machine.
I have an encryption base class which does TripleDES encrpytion. It has two
methods: Encrypt() and Decrypt(). This class, like all my other base
classes, is shared across all projects and clients.

I also have a key generation class which has one method: GenerateKey(). This
generates the key required for the symmetric encryption, and is different
for every client - sometimes different on a project by project basis for the
same client, if that's what they want.

In this way the actual key is not "stored" anywhere. You might say that the
key could be found by disassembly - or, at least, the mechanism for
generating the key could be found by disassenbly - but I take the view that
if a hacker is determined enough to have disassembled my code, they would
have found the key soon enough anyway...

There has to come a point where it's "secure enough", otherwise you'll never
get anything done...:-)

E.g. can you decrypt this:

HgyxhIIBwBb7zY7GBH4xlQ==

?
Jan 3 '07 #3
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ut**************@TK2MSFTNGP03.phx.gbl...
"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>I am trying to find the best procedure for storing keys used for
encryption.

Generally speaking, don't store them at all - devise a mechanism for
generating the same key whenever you need it...
http://msdn.microsoft.com/msdnmag/is...efault.aspx#S9
>This seems to be norm from all the books on building your Web Apps.
Isn't
this a problem as the web.info is cleartext? I would suppose that having
keys (which you would to store/encrypt and get/decrypt from your
database)
in this manner would be dangerous.

I think there's a lot of FUD (fear, uncertainty and doubt) surrounding
this...
Yes.

But if you store information such as Credit Card or Social Security
information - you want that.
>
Firstly, ask yourself who are you hiding this key from...? Your
colleagues...? Your boss...? The office cleaner...?
Yes.
>If you are worried about whether your fellow employees are trustworthy or
not, then you have a much bigger problem then key encryption...

Secondly, is your website's security so lax that your web.config is
visible to the outside world...? Again, if that is the case, then you have
a much more fundamental problem than key encryption...
Even if your security is good - people do get in. Ours is pretty secure but
as you mention below the Professional Hackers may find a way in.
>
Are you perhaps worried about "professional" hackers...? Again, if a
hacker is clever enough to bypass all your security protection and is able
to gain access to your webserver, it probably won't matter much whether
your key is encrypted or not - they'll crack it...
>I am trying to find out how others deal with this. Also, I would need
the
same information for my Apps on the same machine.

I have an encryption base class which does TripleDES encrpytion. It has
two methods: Encrypt() and Decrypt(). This class, like all my other base
classes, is shared across all projects and clients.
This is what I do.
I also have a key generation class which has one method: GenerateKey().
This generates the key required for the symmetric encryption, and is
different for every client - sometimes different on a project by project
basis for the same client, if that's what they want.
At the moment, I am creating one key for all clients. Just a random set of
letters, numbers and special characters. This is passed to both the Encrypt
and Decrypt functions.

I would only be Generating the Key once (or else I would never be able to
decrypt the data). You would have to store something somewhere for the
program to use it (either the data to Generate the Key from or the Key
itself).
In this way the actual key is not "stored" anywhere. You might say that
the key could be found by disassembly - or, at least, the mechanism for
generating the key could be found by disassenbly - but I take the view
that if a hacker is determined enough to have disassembled my code, they
would have found the key soon enough anyway...

There has to come a point where it's "secure enough", otherwise you'll
never get anything done...:-)
I agree here.

I just want to find a pretty reasonable solution.

Thanks,

Tom
>
E.g. can you decrypt this:

HgyxhIIBwBb7zY7GBH4xlQ==

?

Jan 3 '07 #4
"tshad" <ts**********@ftsolutions.comwrote in message
news:uK*************@TK2MSFTNGP03.phx.gbl...
Even if your security is good - people do get in. Ours is pretty secure
but as you mention below the Professional Hackers may find a way in.
And you will never eliminate that threat 100%...
I would only be Generating the Key once (or else I would never be able to
decrypt the data). You would have to store something somewhere for the
program to use it (either the data to Generate the Key from or the Key
itself).
NO! And that's the whole point! You don't "store" anything anywhere - you
just devise a routine / algorithm / whatever which always generates the same
key...
>There has to come a point where it's "secure enough", otherwise you'll
never get anything done...:-)

I agree here.

I just want to find a pretty reasonable solution.
Well, there's an argument which says that there comes a point where your
data is *so* sensitive that access to it over the (public) Internet is
always going to be the wrong solution, irrespective of the technology you
use... That's why e.g. hashes are salted, otherwise I could simply steal
your database, get myself a copy of the Oxford English and use every word in
it as the key until I found a match in your encrypted data. You might think
that's an extreme example (and you'd be right!), but with the power of
computers these days, that might be only a few hours' work...
Jan 3 '07 #5
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:u5**************@TK2MSFTNGP04.phx.gbl...
"tshad" <ts**********@ftsolutions.comwrote in message
news:uK*************@TK2MSFTNGP03.phx.gbl...
>Even if your security is good - people do get in. Ours is pretty secure
but as you mention below the Professional Hackers may find a way in.

And you will never eliminate that threat 100%...
I'm not trying to do that. Just don't want to do something simple like
base64 :)
>
>I would only be Generating the Key once (or else I would never be able to
decrypt the data). You would have to store something somewhere for the
program to use it (either the data to Generate the Key from or the Key
itself).

NO! And that's the whole point! You don't "store" anything anywhere - you
just devise a routine / algorithm / whatever which always generates the
same key...
But then what are you using to Generate the Key? It needs to come from
somewhere, doesn't it? You need to use the same key to decrypt the data.
In your GenerateKey() don't you pass it something? That would have to be
stored somewhere.

Tom
>>There has to come a point where it's "secure enough", otherwise you'll
never get anything done...:-)

I agree here.

I just want to find a pretty reasonable solution.

Well, there's an argument which says that there comes a point where your
data is *so* sensitive that access to it over the (public) Internet is
always going to be the wrong solution, irrespective of the technology you
use... That's why e.g. hashes are salted, otherwise I could simply steal
your database, get myself a copy of the Oxford English and use every word
in it as the key until I found a match in your encrypted data. You might
think that's an extreme example (and you'd be right!), but with the power
of computers these days, that might be only a few hours' work...

Jan 3 '07 #6
"tshad" <ts**********@ftsolutions.comwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
>NO! And that's the whole point! You don't "store" anything anywhere - you
just devise a routine / algorithm / whatever which always generates the
same key...
But then what are you using to Generate the Key?
An algorithm which always generates the same string.
It needs to come from somewhere, doesn't it?
Yes - itself.
You need to use the same key to decrypt the data.
That's right.
In your GenerateKey() don't you pass it something?
No.
That would have to be stored somewhere.
I guess it would - if that's actually what I was doing... :-)

E.g.

private string GenerateKey()
{
return (2 + 2).ToString();
}
Jan 3 '07 #7

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:eB****************@TK2MSFTNGP06.phx.gbl...
"tshad" <ts**********@ftsolutions.comwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
>>NO! And that's the whole point! You don't "store" anything anywhere -
you just devise a routine / algorithm / whatever which always generates
the same key...
But then what are you using to Generate the Key?

An algorithm which always generates the same string.
>It needs to come from somewhere, doesn't it?

Yes - itself.
>You need to use the same key to decrypt the data.

That's right.
>In your GenerateKey() don't you pass it something?

No.
>That would have to be stored somewhere.

I guess it would - if that's actually what I was doing... :-)

E.g.

private string GenerateKey()
{
return (2 + 2).ToString();
}
But this wouldn't work for each customer if each customer had to have a
different key, would it?

Tom
Jan 3 '07 #8
"tshad" <ts**********@ftsolutions.comwrote in message
news:un*************@TK2MSFTNGP02.phx.gbl...
>private string GenerateKey()
{
return (2 + 2).ToString();
}
But this wouldn't work for each customer if each customer had to have a
different key, would it?
???

The encryption base class is constant across all clients and projects.

The key generation class is specific to each client and/or each project.

Jan 3 '07 #9
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
"tshad" <ts**********@ftsolutions.comwrote in message
news:un*************@TK2MSFTNGP02.phx.gbl...
>>private string GenerateKey()
{
return (2 + 2).ToString();
}
But this wouldn't work for each customer if each customer had to have a
different key, would it?

???

The encryption base class is constant across all clients and projects.

The key generation class is specific to each client and/or each project.
So you have a different class for each client/project? Where do you get the
value that you are returning for each client? Is it just some random
number?

Tom
Jan 3 '07 #10
"tshad" <ts**********@ftsolutions.comwrote in message
news:Ox**************@TK2MSFTNGP06.phx.gbl...
>>But this wouldn't work for each customer if each customer had to have a
different key, would it?

???

The encryption base class is constant across all clients and projects.

The key generation class is specific to each client and/or each project.

So you have a different class for each client/project?
Obviously! Otherwise they'd all be using the same key - that's the
absolutely *LAST* thing I want... :-)
Where do you get the value that you are returning for each client? Is it
just some random number?
It's always a 16-byte string, calculated via a different algorithm...
Jan 3 '07 #11

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

Similar topics

4
by: Harold Crump | last post by:
Greetings, I have a requirement of storing some .xml files on a web server. The files will contain financial information like credit card numbers, so I would like to encrypt them. The files...
2
by: Sjaakie Helderhorst | last post by:
Hi, What's the best way of storing a dataset (+/-1000 rows, 9 columns)? I'm using a session-variable but this seems to have serious impact on performance. It's a shop and I'm using the same...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
0
by: Louis Aslett | last post by:
I hope this is the correct newsgroup for this query (if not please give me a pointer to where is best): I understand the theory of normalisation etc and am trying to follow best practices in the...
18
by: Bob Stearns | last post by:
I'm building a web based auction system for multiple clients. I have auctions, items, and invoices I need to assign generated keys for. Since each of these entities is represented by a table, the...
9
by: david | last post by:
I have a class with some business-logic and with every roundtrip, I need an instance of this class, so I have to create it, every time again. That doesn't seem very efficient. I thought it would...
8
by: redeagle | last post by:
I'm wondering what the best practice is for creating a WinApp "wizard" that contains 4 or 5 "steps". Options so far are 1) Single WinForm making various controls visible/non visible at the...
7
by: Tzanko | last post by:
As we all know, there is a 8060 bytes size limit on SQL Server rows. I have a table which requires a number of text fields (5 or 6). Each of these text fields should support a max of 4000...
3
by: at_the_gonq | last post by:
Hello, I am hoping to get some guidance on the following scenerio: I have a password protected site where users have various permissions. Are sessions the best way of storing the user's id? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.