|
Be aware that SHA is not an encryption algorithm. It is a hashing algorithm. The difference is that encryption algorithms can be reversed, hashing algorithms can't.
If you try to use SHA as a base component for your data encryption, there is very little chance that you will ever be able to decrypt your data back to the original input.
There are good reasons why encrypted data is generally longer that the input: It includes information generated by successive iterations though the data and the key. If you need the size of you encrypted data to be the same as your input, then you will heavily compromise the security of that data.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Hi OriginalGriff,
OriginalGriff wrote: Be aware that SHA is not an encryption algorithm. It is a hashing algorithm.
Yes; I am fully aware of this.
OriginalGriff wrote: If you try to use SHA as a base component for your data encryption, there is very little chance that you will ever be able to decrypt your data back to the original input.
It is used in combination with basic 4 round Feistel cypher. It is pretty standard and employed in a number of situations where we want to "secure" a small amount of data. In fact, the formula for it is:
Left = Right ^ First - 8 (SHA-1 (Left + Key))
Right = Left
OriginalGriff wrote: There are good reasons why encrypted data is generally longer that the input
Yes; under normal circumstances I fully agree.
OriginalGriff wrote: If you need the size of you encrypted data to be the same as your input, then you will heavily compromise the security of that data
Also agreed! However, my application must accept a small key with a fixed number of bytes, which will be decoded into a fixed length data block to be used.
However, it must not be given to the end user as plain text, so this method is chosen.
I am fully aware, however, that the level of security is way lower, however, I am not bothered about anyone who has a bit time and knowledge to sit and de-cypher it.
I simply need a basic employment to deter casual tampering!
Thank you,
Stephen
|
|
|
|
|
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
I think you got the KeyedHash translation already (it is just the first 8 bytes of a SHA1 hash).
void DecryptInstID(byte[]InstID)
{
int length = InstID.Length;
if(0 != length % 2) throw new ArgumentException("Must be even length");
length >>= 1;
byte[] Aux = new byte[length];
int i, k;
Left = InstID;
Right = InstID + 8;
for (i = 0; i < 4; i++)
{
KeyedHash(InstID, Aux, length);
for (k = 0; k < 8; k++)
Aux[k] ^= InstID[k + length];
CopyBytes(InstID, InstID, length, 0, length);
CopyBytes(InstID, Aux, 0, 0, 8);
}
}
void CopyBytes(byte[] target, byte[] source, int targetIndex, int sourceIndex, int length){
for(int i = 0; i < length; i++) target[i+targetIndex] = source[i+sourceIndex];
}
Something like that, anyway.
|
|
|
|
|
Hi,
Yes; this sugested code also works, however, after calling it again, I do not get my original data back
If it is not meant to be implemented like this, and I am not going to be able to reverse it,
Is there a better, simple algorithim to use for the following...
1) Accept a small amount of fixed lenght bytes, from 10-20 bytes
2) Produce an encrypted output that is the exact same length as the input
3) Use a private key
I am not concerned about all the debatable security issues as I am aware of them, and simply need something a little more secure than a basic Xor on each byte.
Kind Regards,
Stephen
|
|
|
|
|
For 10-20 bytes, if you generate a new key each time, XOR is fine.
If you want a persistent key, you could use this[^] (shameless personal plug).
|
|
|
|
|
Thank you,
Just what I was looking for!
Kind Regards,
Stephen
|
|
|
|
|
I am trying to scrape the values in these divs to security questions(sec_answers). Of course security question have been removed for security purposes. I would like to use the agility pack, but dont know how it works, any help would be appreciated. The retrieval of information takes lace on a form load and the lays it out for me in the form. Keep in mind I am trying to get the security answer. However this information is generated after the page loads so I am not pulling from a db.
<div class="sec_qaArea">
<div class="sec_title">Security Questions</div>
<div class="sec_question">Name of your favorite pet?</div>
<div class="sec_answer">John Doe</div>
<div class="sec_question">Name of the highschool you graduated from?</div>
<div class="sec_answer">Jane Doe</div>
<div class="sec_question">First car you owned?</div>
<div class="sec_answer">Fail Doe</div>
<div class="sec_question">First company you worked for?</div>
<div class="sec_answer">Doe Boy</div>
</div>
|
|
|
|
|
Is this your page? If so, why can't you just handle the form postback in the normal way? Are you trying to get the values client side (in Javascript)?
|
|
|
|
|
I am using a dynamic usercontrol on multiple forms, and I am trying to reset the form (any one of the forms) and control size by recalling the control using the new command "Control ctrl = new Control()". However it does not reset the size of the control. I tried adding the code I use in a form to the usercontrol as follows:
private Form m_InstanceRef = null;
public Form InstanceRef
{
get { return m_InstanceRef; }
set { m_InstanceRef = value; }
}
This also did not do the trick, how do I call an existing control and get the same instance.
Any help will be appreciated.
Thanks in advance,
Michael
|
|
|
|
|
Hi, a few questions I hope will clarify your query:
1. what exactly do you mean when you say 'dynamic UserControl' ?
a. do you mean that the user interacts with the UserControl and there is an exchange of data between the UserControl and the Form that hosts it ?
b. and/or do you mean that the UserControl fires Events that the Form subscribes to, and/or depending on what data is sent to the Form, then the Form calls public methods on the UserControl ?
c. maybe all of the above ?
2. you are describing a scenario where you have multiple forms each with an instance of the UserControl ... yes ?
3. when you say 'reset the Form,' exactly what do you mean ?
a. set all the user-entered values on the Form to some default value ?
b. set only the UserControl on the Form back to its default state ?
b. destroy the Form and re-create it, but somehow persist some user-entered values on the UserControl ?
4. by 'reset the control size,' do you mean reset the UserControl on the Form back to some original size ?
Sorry if these questions seem 'picky,' but the clearer you describe the scenario, the quicker you'll get good answers, I hope.
"In the River of Delights, Panic has not failed me." Jorge Luis Borges
|
|
|
|
|
By dynamic I mean I setup the usercontrol by my program not by dragging it from my toolbox.
I can choose how many times I wish for this control to be added to the form as follows:
this.Contol.Add(usercontrolname)
this is a chart for the stock market.
1 control for the stock price per form.
1-3 controls for indicators per form.
1-3 controls for oscillators per form.
Because I can choose multiple stocks to monitor each with its own form, I resize the forms.
The more stocks I choose to monitor, the form resizes per set ratio depending on quantity and size of screen.
Also, if I choose multiple indicators or oscillators I resize all charts per form (meaning price, indicators, and oscillators) as set ratio of number of charts.
If I am going from 4 stocks to 5 I would divide the screen differently and resize the forms. Therefore I resize the controls within. Just from talking about this I could setup on building the form the %size and postion of the control and it would automatically reset the controls within on resizing the form.
But if I want to add or delete an indicator then I would want to reset the size and positions of the individual controls as a set formula to maximize the space for the entire form.
I hope this is more specific.
Thanks,
Michael
|
|
|
|
|
Then you'll need to come up with a 'formula' for the 'optimal' size of each control.
A good start would be to take the client size area of the form that's available for the controls, then subtracting the left and right offset (the distance of the controls to the edges of the form).
Then you have the 'working area' that can be used for the controls. If you have N controls you want to place in a row, and X pixels spacing in between controls you have ControlWidth * N + X * (N - 1) == WorkingArea_Width . Solving for ControlWidth gives you the 'optimal' width of each control.
Then you just have to set the control size on each, for instance if you stored the dynamically created user controls in a list:
private List<MyUserControl> mControls = null;
...
mControls = new List<MyUserControl>();
...
mControls.Add( myNewUserControl );
...
foreach (MyUserControl ctrl in mControls)
{
...
ctrl.Left = ..; Ctrl.Top = ..; Ctrl.Width = ..; Ctrl.Height = ..;
}
I hope I managed to properly explain what I mean.
|
|
|
|
|
I have already calculated all the sizes needed, however I do it for each form, which is redundant.
I think I understand you correctly, if I place the correct claculation in a list every time the form is resized it refers to the list and resizes the control accordingly as a percentage or point, width, height, etc.
I think this will wok great, thanks.
Michael
|
|
|
|
|
Hi, I think you got a good response from MicroVirus, but I will add, based on the assumptions we are talking about an application built-on .NET / WinForms:
1. one way to address resize in general in .NET is to set the Anchor or Dock properties of the hosted Control/Form in a way that when the host container (Control, Form, UserControl) is re-sized, the hosted things automatically 'do the right thing' in terms of re-sizing. I'm wondering why that strategy would not work for you.
2. on the larger level ... architecture ... it sounds like what you are doing involves a lot of either Forms or Controls, or UserControls; have you considered using a meta-container, like a DataGridView, FlowLayout, or TableLayoutPanel, all of which can host Controls of different types, one where changing the size of its virtual rows or columns can take care of re-sizing issues, or inserting a new object that requires a change in its hosted row and or column size can have this change automatically handled.
good luck, Bill
"In the River of Delights, Panic has not failed me." Jorge Luis Borges
|
|
|
|
|
I was thinking about point 1 myself too. My 5
|
|
|
|
|
Hi guys. I'm trying to write an add-on for Visio... but I'm running into problems. Basically, I just don't know how Visio stores the data for shapes... and my searching hasn't given me any good examples that seem applicable.
As an example, if I create a database diagram and drop a "Table" master onto the sheet... I want to be able to click the add-on and it read all of the properties of that table. That is, I want it to know the name of the columns, their data types and so forth.
Can anyone give me a clear example of how this is done? So I've tried enumerating the shapes on the page, but I only see a single shape and it describes the single column I added.
Thanks, in advance.
Sam
|
|
|
|
|
I have written a program for the stock market in C#. I am now trying to put the data in charts, I keep seeing a lot of charts using ASP, my question is what are the advantages for using another language other than C# with .net forms. I am much more familiar with C#, what are the pros and cons for using another language, any recommendations please do not limit to ASP and C#.
Any advice will be appreciated
Thanks in advance,
Michael
|
|
|
|
|
C# can basically do what any other language can do.
You are already comfortable with it, so you should probably think about sticking to it rather than moving to another language.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
Okay, I have had this problem in the past. However, the projects were small personal projects which I wrote at home, for fun. Now I am writing applications here at work. And it is beginning to hinder the process greatly.
I have noticed that whenever I use a custom control (or, for example, the free DevExpress XtraEditors controls which I registered for and downloaded) in any project, I receive the error:
"Unable to copy file "obj\Debug\LpsApp.exe" to "bin\Debug\LpsApp.exe". The process cannot access the file 'bin\Debug\LpsApp.exe' because it is being used by another process."
When I first open the project and I work on a form which uses a custom control it is okay. However, once I make a change and re-build the project a few times I begin to receive the error message. Like, every time from then on. Once I close VS2010, delete the bin/Debug directory and restart, it works fine again for a few builds. Then it goes back to the same crap. This is highly frustrating.
I have another project which was perfectly fine, for months. That is, until I made an upgrade and it involved a custom control from right here on good ol' CodeProject. I then began to receive the same error message. But as long as I do not open the forms which use them and make changes, and I do not make changes to the custom control itself or its code, everything is fine. I restarted the current project a while ago and I have been working on a different feature. And it has been flawless.
Why does a custom control do this? Is there any way around it?
I have tried deleting the .SUO file, the 'bin' folders, the 'obj' folders. I have tried the pre-build event which renames the file with a '.locked' extension. As well as a few other "solutions" which I found online. They work for two or three builds and then it is right back to the same thing.
Thanks CP.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
To me the scenario you describe is slightly ambiguous: are you describing:
1. you have Project 'x' open in VS, and you add a reference to the compiled dll of UserControl 'y,' then use it in 'x, and then, after some usages, you get the compile error.
... or ...
2. you have Project 'x' open in VS, and the source code for UserControl 'y,' open in that Project, then: you create an instance of 'y, either by drag-dropping from the ToolBar at design-time, or in code at run-time, which you then use in the code, and then you get the compile error.
If #2, then does the error occur reliably when you have made changes to 'x, but have not changed the UserControl source code, or, does it happen after you have changed the UserControl source ... or does it happen in both cases.
The cases where I have experienced the same error have usually involved compiling in 'DeBug mode, and having the vshost.exe enabled in the Project preferences, and then some error has occurred at run-time which has left a window open by mistake, in which case: sometimes I have to open the TaskManager and kill that process.
best, Bill
"In the River of Delights, Panic has not failed me." Jorge Luis Borges
|
|
|
|
|
Thank you for responding and explaining a bit. I apologize for the ambiguity. The scenario is like #2, I guess.
I just now went back to it. And I built the solution, made a change to one of the properties of the DevExpress control (in its parent form), hit Build again and it threw the error message. So why is it that changing something for the control causes this? Where is it getting stuck?
Process Explorer (from SysInternals) shows that Devenv.exe is the only process which is holding onto LpsApp.exe. Its own process is not running. Not in Task Manager either. If I close VS and restart it, it works for a bit until I make these changes. ???
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
I'm a little thick in the head at 02:58 GMT +7, so bear with me ...
The key issue I'd like to know here is did you alter the source code of the DevX control.
When you say "made a change to one of the properties ... (in its parent form) ... I assume you altered some attribute, some value, some setting, in the instance of the DevX Control on a Form ... yes ?
The other question is about to what extent this problem is reliably reproducible: can you say, for a fact, that if you alter property 'x' of the DevX control, build the app, run it, then quit the app, that this will fail after exactly #n times.
If the there is a varying result of failure to build/run given the same initial conditions, then I think a valid hypothesis would be that it was a problem with either the DevX control, or Visual Studio. If it's in the DevX control, I wonder what you could do by single-stepping through a 'run' ... if you can get that far. If it's breaking in the build, big problem.
good luck, Bill
"In the River of Delights, Panic has not failed me." Jorge Luis Borges
|
|
|
|
|
BillWoodruff wrote: I assume you altered some attribute, some value, some setting, in the instance
of the DevX Control on a Form ... yes ?
Yes, I simply alter a value in the Property Editor while using the Forms Designer.
BillWoodruff wrote: The other question is about to what extent this problem is reliably
reproducible: can you say, for a fact, that if you alter property 'x' of the
DevX control, build the app, run it, then quit the app, that this will fail
after exactly #n times.
It will fail the first time I attempt to run the application after I make a change to a property of the DevExpress control. It does the same thing for EVERY DevExpress control. It also does the same for a custom control which I acquired here on CP. One modification to the control in the designer and it flips out. :P
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Hi Matt, In this case I would definitely report an issue to DevX, and check on their forums to see if anyone else is experiencing this, or if there's any fix. While I have not used DevX controls myself, they do have a great reputation for support, and quality, imho.
One final question: when you first used the DevX free controls, did they require conversion by VS 2010 to be compatible with whatever FrameWork version you are compiling against. If so, did you look at the conversion error report, if there was one: might be a clue there ?
best, Bill
"In the River of Delights, Panic has not failed me." Jorge Luis Borges
|
|
|
|
|