|
Hi everyone,
I'm having a strange problem with DES encryption in .NET (DESCryptoServiceProvider). I'm using 3 implementations of DES, one in .NET, another in JavaScript and one in Java.
I'm encrypting the same short string with the same 8-byte key, using ECB mode. ALl implementations will return a 16-byte cipher text (two 64 bit blocks). The problem is that the first 64-bit block of the cipher text is the same for all three implementations, but the second 64-bit block is different in C#. THe same thing happens when using CBC with initialization vector.
I don't think that there is a problem with my C# code, another C# sample I have tried returned the same results, but here is the code I'm using. I have no clue what to do
MemoryStream memStream=new MemoryStream(100);
DES des=new DESCryptoServiceProvider();
des.Mode=CipherMode.ECB;
CryptoStream encStream = new CryptoStream(memStream, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write);
encStream.Write(Encoding.UTF8.GetBytes(strMessage), 0, strMessage.Length);
encStream.Close();
byte[] desEncrypted=memStream.GetBuffer();
string strEncrypted=BitConverter.ToString(desEncrypted, 0, i);
memStream.Close();
Thanks for any ideas in advance,
Rado
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
OK I figured that out. This is so ridiculous, and it happens to me all the time. I spent at least 2 hours with it yesterday in the evening, and now I post a question to the C# forum and voila, in the next 5 minutes I find that it has been caused by a different PaddingMode - .NET uses PKCS7 by default, whereas both JavaScript and Java implementations use zeros.
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
Hi all,
I have this Error message when i try to run debug on my program "The Machine Debug Manager Service is disabled". Is this caused by the program being too big or is there an option to enable the debug. Please help.
|
|
|
|
|
I was added the controls in the DataGrid at the run time using TemplateColumn class. I was added Two Columns, one coloum controls is DropDownList and other one is TextBox. I need , While i am clicking the DropDownList at runtime, the corresponding SelectedItem to be display in TextBox . But i couldn't get it.
how i get the data from DropDownList? if you have send me the sample coding.
|
|
|
|
|
There were many controls in my form. When I clicked one button,then showdialog. The form had flash obviously. How to do it?
Thanks.
|
|
|
|
|
Huh?
Could you please tell us what you want in a different way? I don't think anyone can guess what you want from this question. In case your english is not good enough please try to ask someone for help.
mav
|
|
|
|
|
I put many controls in form. When call showdialog() method, the form flash obviously. the control been show one by one. In VC#.net, has some method that ListBox's redraw method in MFC?
How to do it?
Thanks.
|
|
|
|
|
What has a flashing form to do with ListBox redraw?
If your problem is that a Form's painting gets slow with _many_ controls, well, that's the way it is. For a sane number of controls there's no flashing.
How many controls are on the Form?
I'd suggest you re-design the UI to have less controls. If .NET has problems drawing so many controls your users will have problems handling so many controls.
Or you try to inherit from Form and perform double buffering yourself, but I'm not sure if this will work.
mav
|
|
|
|
|
Perhaps your dynamically adding the controls to the form yourself rather than having used the form designer to place the controls? If so, may sure you call SuspendLayout() before you start adding the controls, and ResumeLayout(false) when you're done.
We have a situation where our form took a long time to 'paint' the controls, even with suspending and resuming the layout. After lots of messing, we found that filling the form with a panel (dock = Fill), making the panel .Visible = false, adding all of the controls into the panel, and then making the panel .Visible = true looked much better for the user - and took less time to execute (essentially a form of the double buffering that mav.northwind mentioned).
|
|
|
|
|
How do u handle export/import features in custom application?
use DTS Packages? How to import Excel Data into my application by using DTS? Any Idea? I'm using C#, SQL Server 2000.
|
|
|
|
|
OK, here is my situation in more detail. I have .NET framework version 1.0.2914 and version 1.0.3705 and Visual Studio .NET Professional all running on my Windows 2000 Professional computer. I checked it by going to Control Panel, and then Add/Remove Programs, and they were all listed. I installed my fully-compiled and partially-developed C# windows application on a Windows 98 computer with version 1.0.2914 of .NET installed. When the application I have been working on and compiled on the Windows 200 Professional computer is run on a Windows 98 computer with version 1.0.2914 installed, I get an error.
How do I identify which version of .NET the application is compiled with using VS.NET, and could I change the version that VS.NET uses to compile the application? Where would I go to identify the version and where to change it. Also, there is now a version 2.0 available. Could I install version 2.0 in both places, and if so, should I then delete the other versions of .NET. Finally, could I then assign VS.NET to use version 2.0 of .NET framework?
|
|
|
|
|
|
Nick Parker:
I read the articles that you had recommended. While the articles covers how to get different versions to redirect to different .NET framework versions running in parallel, it still does not seem to explain how to get Visual Studio .NET to run the .NET framework version that I would select for it to compile in VS.NET. I would prefer to run the application on .NET 2.0, and if the target computer does not have 2.0 installed, I would direct the installation bootstrap loader to install it.
BTW, I installed the beta version of .NET 2.0 on the Windows 98 computer, and now the simple form works properly. Now I would like the Visual Studio .NET to run using the .NET 2.0 beta instead of the installed version that accompanies the VS.NET installation. Is it possible to get the VS.NET to compile using the .NET 2.0 beta, and if so, how could I change the configuration file, or a setting in VS.NET to choose 2.0?
|
|
|
|
|
I built a golf tournament management application about a year ago in C# .NET. I had context sensitive help through the .NET Help Provider that accessed a lone .chm in the application directory. I had a web browser that allowed users to surf the web within the application.
Now all of a sudden I can no longer view help topics through F1 in the app. And I can no longer browse the web within the app. The help module displays the TOC and index but cannot display topics, the screen stays blank with a downloading dialog box popping in and out every time I hit a topic. The web browser wont even work with the same downloading dialog box flashing every time i try to use the browser.
To make matters worse I created a blank project that utilized the web browser and help provider and it worked like a charm, but as soon as i try to integrate it with my golf app it no longer works.
I have looked and looked but cannot find a solution. It may have something to do with windows security (IE security update) and the SHDocVw.dll as they are a factor in both problems. I am at a loss.
Please Help
MIKE
|
|
|
|
|
Hi,
Could anyone help me? I want to know what happen to parameter variable when a procedure/method is invoked. Is it static allocation or dynamic allocation? Is there a way to get parameter pointer?
Thx.
|
|
|
|
|
mineminemine wrote:
I want to know what happen to parameter variable when a procedure/method is invoked. Is it static allocation or dynamic allocation? Is there a way to get parameter pointer?
If you have a method that takes a struct as its parameter it will receive a copy of the struct. If it takes a non-struct object it will receive a new object variable pointing to that object (remember, an object variable is a pointer). However, you can use the ref[^] (or out[^]) keyword to let the method access the original struct/object variable. Of course you can also use pointers in C#[^] directly if you declare your code as unsafe[^] but I recommend to avoid this whenever it's possible.
Best regards
Dennis
|
|
|
|
|
Hi all, I posted this on the General Discussion board, but it seems a little dead in there. Hopefully this isn't too offtopic for this board.....
I was hoping for some advice on 'best practices' regarding the design of an app I'm working on. It's a subscription-based web app in C#. Member data is stored in a DB table cunningly named Members. I've implemented a fairly simple Member class which essentially wraps access to a row in the table, with functions like:
static public Member FetchFromDB( int iMemberID );
public void UpdateInDB();
etc.
and getters/setters to map the contents of the Members row, like:
public DateTime ExpiryDate{ get{ return _expiryDate; } }
public StatusEnum Status{ get{ return _status; } }
etc.
I'm happy with this class as described so far. It does one job, maintains a constant level of abstraction/encapsulation, etc. However, My app also needs functionality like 'Check whether a member's ExpiryDate is in the past, and if so update their Status to Expired', or 'Update LastOnline to now'.
The way I've been doing this so far is to add methods to Member such as UpdateLastOnlineToNow(), CheckExpiryDate(), etc. Obviously this works fine, but I'm finding myself adding more and more 'utility' methods to Member, and I'm starting to think that Member has a 'bad smell' - it's still a wrapper for the DB, but it's also getting more and more higher-level functionality mixed into it.
This class is just an example, I'm also getting similar bad smells with various similar classes in my app (Message, for example, which encapsulates my message sending/receiving system).
So my question is, what do all you wise and esteemed CPians think? Have I been reading my Patterns books a bit too religiously? If I not, what would be the best way to refactor this? One thought I had is to break Member out into 3 classes, a low-level wrapper to the DB, a high-level wrapper that uses the low-level wrapper internally, and a utility class that also uses the low-level wrapper. Is this overkill?
Any other suggestions (or any thoughts at all) gratefully appreciated!
Cheers,
Pete
|
|
|
|
|
I suppose it all depends on the coder's style. I'd do it this way:
1. I would create a Member class which would be an abstraction of a "real life" Member, or in other words, a Member object. It would have all the cunningly named strongly typed properties like string Name, int Id, date ExpirationDate, etc, and not much else. U could even make it a struct, but if it gets passed around a lot, it might be better to keep it as a class.
2. Then I would create a DBManager Class that would fetch, insert and update Member instances from/into the DB. This would be like your barebone original Member class but all methods/properties would be strongly typed to the Member class when necesarry:
public Member GetMember(int memberId)
{
}
public void UpdateMember(Member changedMember)
{
}
etc...
3. And finally I would create a utility class that would perform all the functionalities upon the Member instances such as the ones you mentioned above: "UpdateLastOnLine", etc. All changes in the member instance would then be updated into the DB through the DBManager.
public void UpdateLastOnLine(Memeber member)
{
}
etc...
Hope this helps....if not quite your coding style, it might still give u some ideas. It might be an overkill for the true requirements of your app, but I always try to make my stuff in a orderly and structured fashion, even if its really not necessary.
|
|
|
|
|
Hi Skynyrd,
Thanks for the response.
To clarify, the DBManager would just be responsible for wrapping the Member table in the DB, or wrapping all the tables?
I'm also not sure how the coupling would work with the three classes you mention. The way I see it, Member should be hiding/abstracting over some of the internal properties of a Member. For example, LastOnline shouldn't be settable, it should just be updatable to DateTime.Now. That being the case, both DBManager and the utility class would need access to the internals of Member, and I'm not sure how best to accomplish that. That was why I thought of having a low-level wrapper (which would expose those internals), and then a higher-level wrapper, which would be, as you say, a Member 'object'. But with that design, I'm not sure if it's feasible to have a seperate utility class. The utility class would need access to the internals, but the client of the utility class presumably wouldn't be able to access them. If this were C++, I'd consider making the utility class a friend of the lower-level wrapper, but AFAIK that isn't possible in C#.
I hope you don't think I'm being argumentative about this, I'm honestly just trying to figure the best way to design this sucker. I do appreciate your input!
And yes, as you say, all of this probably /is/ overkill for the app, but like you I like to try and keep my design as clean as possible (within reason!).
Cheers,
Pete
|
|
|
|
|
DBManager could be used for wrapping all tables in the DB. If ur only updating and selecting, u could still keep the class public interface pretty simple and wrap all tables. It also depends on how u are encapsulating other objects equivalent to Members. U could even use a generic object and through Reflection and Attributes obtain the properties of the objects that represent fields in your underlying DataBase tables and thus create a very decoupled DB Manager with signatures like: Update(object changedRegistry) etc. (U could create a custom TableFieldAttribute(string fieldName) to mark the properties that represent real fields in the DB tables in order to acheive this...this comes in handy if u expect using additional properties in these objects that dont necessarily represent underlying fields).
Concerning the threeway implementation, ur right about the LastOnline method, this is probably where overkill comes in :p. The utility class would not be really necessary if only these type of methods appear. Maybe u could keep the implementation to just two classes (DBManager and Member) and Member would take care of methods similar to LastOnline, as it is logical that only Member should have access to the LastOnline setter. On the other hand, if some utilities require extensive work with Member instances then the threeway solution would be plausible, keeping methods like LastOnline in the Member class as a tool for the Utility class.
|
|
|
|
|
I think the DBManager concept is interesting, particularly the use of Reflection and Attributes. However, I think it /would/ be overkill in this case Also, it could get complicated for certain things - e.g. the Member table contains pictures, which I don't want to fetch every time I get member info. Obviously, the DBManager concept could be extended to cover that kind of thing, but then we're certainly deep in overkill land.
The reservations I have with the design you suggest is that I'm still left with a Member class that's got various levels of abstraction. While on the one hand it's exposing simple getter/setters, and it's also doing higher-level abstraction utility functionality - e.g. UpdateLastOnlineToNow(), CheckExpiryDate(), UpdateWithInputFromWebForm() (I should have mentioned that one earlier I guess).
Any other suggestions No, seriously, thanks for the input. It's been helpful. Keep it coming
Cheers,
Ptete
|
|
|
|
|
I'm not sure that the Member class should not be able to perform some simple higher-level abstraction utilities. If the actions are solely meaningful to the member class, then there is no problem in implementing them in that class.
For example, LastOnline and CheckExpiryDate might be only meaningful to the member class. Thus it would be reasonable to implement it in that class, even if its a higher level abstraction. Particularly, I would implement the CheckExpiryDate() as a boolean property HasExpired (question of tastes here ).
On the other hand, more general functionality like UpdateWithInputFromWebForm might be a more general utility that might be meaningful to more objects than Member instances and should be implemented in a Utility class. My first design wouldnt be valid anyhow, as the Utility class should not be strongly typed to the Member class, and the update could and should be done in a generalize way (again with Reflection through a Dictionary collection: property name - new value for example u could acheive this)
To make it short, what I always try to do is isolate all DB Management from the real objects I'm using in my application. In your original design, your Member class was implementing the DB update logic too, and I think thats where I would change the abstraction of the objects. Implementing the utility class depends again on how complicated your app is really going to be, but I dont think implementing high level abstractions in the Member class is a design fault if those utilities are only applicable to the Member class.
I think we need some second view about this, so any more suggestions are welcome
|
|
|
|
|
There's a new possibility in the System.IO that is accesing to Port Coms: System.IO.Ports, I'm not good with delegates and I'm trying to make a program that when receives a data from the serial port makes an event:
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
ptocom.ReceivedEvent +=new SerialReceivedEventHandler(ptocom_ReceivedEvent);<br />
}<br />
<br />
void ptocom_ReceivedEvent(object sender, SerialReceivedEventArgs e)<br />
{<br />
<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
SerialPort ptocom = new SerialPort("COM1", 9600, System.IO.Ports.Parity.None, 8, StopBits.One);<br />
string buffer = "j";<br />
ptocom.Open();<br />
ptocom.ReadTo(buffer);<br />
}
Thats all I could discover about using this new possibilities but It doesnt work, any Idea?
Juan Pablo García Coello. Electronic Engineer.
Projectist at the Electronic Dept.Instituto de Astrofísica de Canarias. Spain
|
|
|
|
|
I think your problem is, that you subscribe your event handler during the handling of the Form.Load event, but the SerialPort object isn't created until button1_Click gets called or more likely is newly created there, cause otherwise the handler subscription would crash with null reference exception.
So your event handler isn't subscribed to the SerialPort object you create in click event handler and therefor doesn't fire, but to some instance created before the Form.Load event.
www.troschuetz.de
|
|
|
|
|
There's a new possibility in the System.IO that is accesing to Port Coms: System.IO.Ports, I'm not good with delegates and I'm trying to make a program that when receives a data from the serial port makes and event:
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
ptocom.ReceivedEvent +=new SerialReceivedEventHandler(ptocom_ReceivedEvent);<br />
}<br />
<br />
void ptocom_ReceivedEvent(object sender, SerialReceivedEventArgs e)<br />
{<br />
<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
SerialPort ptocom = new SerialPort("COM1", 9600, System.IO.Ports.Parity.None, 8, StopBits.One);<br />
string buffer = "j";<br />
ptocom.Open();<br />
ptocom.ReadTo(buffer);<br />
}
Thats all I could discover about using this new possibilities but It doesnt work, any Idea?
Juan Pablo García Coello. Electronic Engineer.
Projectist at the Electronic Dept.Instituto de Astrofísica de Canarias. Spain
|
|
|
|
|