473,382 Members | 1,365 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,382 software developers and data experts.

protecting objects from being changed

Is there a way that is already built into .net 3.5 that will let me protect
an object from being modified when the object is public?

Jun 27 '08 #1
6 1399
On Apr 15, 2:37 pm, "Andy B" <a_bo...@sbcglobal.netwrote:
Is there a way that is already built into .net 3.5 that will let me protect
an object from being modified when the object is public?
Simply put: don't expose any way of making any changes. Make all your
properties readonly and make sure your methods don't change anything.
Making all member variables readonly goes some way to doing this,
although it's less clearcut if one of your member variables is of a
mutable type itself (e.g. StringBuilder).

It's unfortunate that C# doesn't have more support for creating and
checking immutable types - I know it's something that the design team
are considering for a future version.

Jon
Jun 27 '08 #2
Is there a way that is already built into .net 3.5 that will let me
protect an object from being modified when the object is public?
I'm not quite sure what you mean by modifying an object, except for modifying
it's state (ie. fields). You should encapsulate your fields with properties.
Properties can be read-only (not set), or a mix of a public get and more
hidden set (private,protected,internal).

public class OpenClass
{
private string _name;

public string Name
{
get
{
return _name;
}
internal set
{
_name = value;
}
}
}
Jun 27 '08 #3
I have an object that when it's IsSigned property is set to bit 1, can't be
changed. Otherwise if it is set to 0, it can be changed in whatever way is
needed. This check would need to be done before putting the object inside a
database and after it is pulled out of the database as well. The object will
be serialized into an xml format and it's IsSigned state will be put into a
database table column seperate from the object itself. I.e. in the table
called objects, I would have the columns Id, IsSigned, IsFulfilled, IsPaid,
Object. I guess I'm just looking for some easier way of doing something like
this since the object already has over 60 public properties built into it.
These 60+ properties are split between 18 sub classes and data types.
"Morten Haug" <mo****@haugern.netwrote in message
news:e9*************************@news.lyse.net...
>Is there a way that is already built into .net 3.5 that will let me
protect an object from being modified when the object is public?

I'm not quite sure what you mean by modifying an object, except for
modifying it's state (ie. fields). You should encapsulate your fields with
properties. Properties can be read-only (not set), or a mix of a public
get and more hidden set (private,protected,internal).

public class OpenClass
{
private string _name;

public string Name
{
get
{
return _name;
}
internal set
{
_name = value;
}
}
}


Jun 27 '08 #4
On Wed, 16 Apr 2008 04:55:43 -0700, Andy B <a_*****@sbcglobal.netwrote:
Do you have a link to the pgp encryption stuff? And I forgot to mention,
there are 2 different people signing the document (the company and the
customer).
http://www.google.com/search?q=pgp+signing

I'm not sure I understand the "2 different people signing the document".
You're not specific about what effect this should have, or how you expect
the two to interact. Are both people supposed to be able to access the
document after it's been signed? Can you simply store two encrypted
versions of the document? Alternatively, is it okay for the company to
retain a copy of the customer's encryption key?

That requirement will certainly make your problem more complicated,
whatever the answers to those questions might be.

Pete
Jun 27 '08 #5
>I'm not sure I understand the "2 different people signing the document".
>You're not specific about what effect this should have, or how you expect
the two to >interact.
The company and the customer are supposed to sign the document. When the
form is filled out by the company online, a username and an encryption key
(a password as the customer would know it) is sent to the customer. They are
directed to login, view and sign the document (which has already been signed
by the company). After the company signs and presents the document for the
customer to sign,, for some reason the customer needs some changes made to
the document (the "form attached to the document"), the company should be
able to make the changes to satisfy the customers changes to the "form" and
then present it back to the user for signing. I think this possibly might be
a legal issue though since the standars for e-signing act of US law states
that after signing the document, it should be checked to make sure it can't
be changed. Is this before both people sign, or after both people sign?
>Are both people supposed to be able to access the document after it's been
signed?
Yes, both customer and company have to be able to view the document. There
might be a slight issue though. When the company fills out the document,
they have to sign it before it is presented to the customer before the
customer signs it. So, basically, even though the company has already signed
the document and commited to provide the services outlined in the document,
the customer still must be able to view and sign it for themselves. We
already found that 2 encryption keys for each document would be required -
one for customer and one for company.
>Can you simply store two encrypted versions of the document?
No, this method is not possible. Disk space is expensive and the database
needs to be as small as possible. Each transaction (document signing) will
roughly take about 2-3k in size. So, there can only be 1 copy of the
document for each transaction.
>Alternatively, is it okay for the company to retain a copy of the
customer's encryption key?
Yes, that is entirely possible. The only restriction to this is that if the
customer forgets or loses their security key (password), it can't be
retrieved or reset. The conciquences to losing or forgetting the security
key is that the customer will not be able to view their signed documents
again (since most security signing services or programming addins do the
same sort of thing).


Jun 27 '08 #6
On Wed, 16 Apr 2008 16:44:37 -0700, Andy B <a_*****@sbcglobal.netwrote:
[...]
>Alternatively, is it okay for the company to retain a copy of the
customer's encryption key?

Yes, that is entirely possible. The only restriction to this is that if
the
customer forgets or loses their security key (password), it can't be
retrieved or reset.
Well, then I'd say that means it's not possible. After all, if the
company retains a copy of the customer's key, they can always retrieve
that copy. Or if they can't, there's no point in retaining it. :)

I also don't know what world you live in where "disk space is expensive",
but I suppose that's one of those relative things.

Other than that, the requirement that the document be signed by both
parties, while still retrievable by either party individually, is way
beyond anything I'm able to offer. I'm pretty much out of answers; you
need an expert in the field, and that I definitely am not.

I know that the experts in cryptography seems to be able to solve all
sorts of intuitively intractable problems. Maybe there is in fact a
reliable encryption scheme in which two different keys (and only two
different keys) can be used to decrypt an encrypted document. But if
there is, I don't know what it is.

Which isn't to say you won't get an answer in this newsgroup. It's
possible you would...I've seen some esoteric crypto stuff discussed here.
But for sure, I'm not the guy to give the answer. Sorry...

Pete
Jun 27 '08 #7

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

Similar topics

0
by: James Sleeman | last post by:
Hi all, i just spent an hour rifling through code to find the cause of a problem only to find it's an oddity with serialization and recursive objects, so figured I'd post for the next person who...
24
by: Yang Li Ke | last post by:
Hi guys! Anyone know a way so that users purchasing my scripts would not be able to share them with other people ? Yang
12
by: Roland Hall | last post by:
I read Aaron's article: http://www.aspfaq.com/show.asp?id=2276 re: protecting images from linked to by other sites. There is a link at the bottom of that page that references an interesting...
11
by: thechaosengine | last post by:
Hi all, I have a very general but quite significant question about objects. My question is, when should I create them? I know thats a crap question so let me explain a bit further. Lets...
6
by: Howard Kaikow | last post by:
I'm doing a VB 6 project in which I am trying to protect against type mismatch errors. Is the process any different in VB .NET? Here's what I'm doing in VB 6. I have an ActiveX DLL. The...
6
by: Roman Werpachowski | last post by:
In a recent thread http://tinyurl.com/8n7fe I asked about preventing the user from deleting the object pointed to by a pointer/reference. Now I would like to ask about a different aspect of this...
47
by: Max | last post by:
Due to the behaviour of a particular COM object, I need to ensure that a request for a particular ASP page is finalized before another request for the page is processed. Does IIS have a way to...
22
by: flit | last post by:
Hello All, I have a hard question, every time I look for this answer its get out from the technical domain and goes on in the moral/social domain. First, I live in third world with bad gov., bad...
27
by: SasQ | last post by:
Hello. I wonder if literal constants are objects, or they're only "naked" values not contained in any object? I have read that literal constants may not to be allocated by the compiler. If the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.