|
Hello Code Project Community!
Our Case:
The Customer has to unlock his application by passing a valid combination of a username and his serial number/key which we generated for him, using our own key generator.
Example:
Username: Jack Miller
Serial-#: 0954F43A-90C4AC01-F09951CF-9012387A
Currently we are doing a simple check: We encrypt the Username with a hardcoded salt and check if the result equals to the serial number (this is how we in fact generated it )
We dont need a perfect security here and we know everything can be bypassed but this is currently really enough.
But now we would like to keep additional information inside of the serial number, for example, a License type (would be enough if we have numbers for it from 1 = demo to 4 = enterprise) and also a date for evaluation versions.
So we would like the user to type in his Username and his Serial, and we could show him, that the Serial provided is a demo key, valid until 05.06.2005, for example.
There must be a good practice or strategy how to hide this information inside of the serial number, but we have no idea, because we have to keep the length of the serial number! Can you help?
Thanks in Advance!
Thomas
|
|
|
|
|
Hi!
From your description you're using a one-way encryption, where you only verify that a calculated hashkey matches the one in your serial number.
To be able to do so you don't need a reversible algorithm.
In order to decode the additional information you would need a reversible algorithm. I haven't found a way to decode information without placing the information on how to encode the same information in the same program. So it's always possible to encode modified information in a way that matches your algorithm. Your serial would be breakable quite easily.
The solution I've found to suit my needs best is to use a plain-text license file (XML) that contains a private key signature.
That way I can put arbitrary information into the license file and only have to give the public key in my program.
I can verify that the signature matches the license file's contents (i.e. the contents have not been tampered with) and don't have to worry that anybody can use the public key to compute a new signature.
Regards,
mav
|
|
|
|
|
Hello mav,
first of all thanks for your reply. i guess this is a not so bad attempt how to keep the key quite secure. but i am also missing the direct context to my problem...
Ok, i wrote my little encryption library and just keep the key hardcoded. i know that its easy to retrieve the key by disassembling or just debugging the libraries but currently that doesnt matter at all. So currently i am using the TripleDES symmetrical provider to encode the data. in contrast to the MD5 hash algorithm, where i always get very nice 32-bit strings, which are very usable for serial numbers, the encryption results in varying lengths of the encoded string as "ugly" Base64 Encoded Strings or Hex-Strings, which look better but are also longer.
ok now i could create my object which holds all the information needed, it could be xml-serialized then, and encrypted. but i get a very long encrypted string, much to long: We will send the most of our serials by Fax! I wonder, how i could keep the Serial Number still quite plain, maximum 32-40 Characters, and keep the information stored?
Regards,
Thomas
|
|
|
|
|
If you don't care about anybody finding out the algorithm, key and IV, then the symmetric algorithms in the framework are perfectly OK.
But the size of your encrypted information will be depending on the input data size. I tried encrypting a name followed by a separator character ('#') and a date and ended up with a Base64 encoded string of length 44 to 56.
I didn't manage to reduce the size of output by varying the key size.
Of course, Hex-strings are easier to type than Base64, but due to the limited alphabet are also longer.
You could work on the input data, though.
For example, instead of encrypting the whole name as it is you could just create a hashcode and encrypt this. Follow the hash code with a separator character and append the additional information you want to store.
That way you should be able to reduce the serial key reasonably.
Regards,
mav
|
|
|
|
|
ok, so far... thanks for the great support! * thumbs up *
|
|
|
|
|
Hello,
How do a strip Alpha-Numeric chars from a string?
Thank you.
|
|
|
|
|
I would recommend using regular expressions (System.Text.RegularExpressions ). In particular, look at System.Text.RegularExpressions.Regex.Replace method.
Your regular expression would look something like:
string myString = "Blessed! Happy! Fortunate! Are those who delight in the Lord."
string nonAlphaNumericString = Regex.Replace(myString, @"\w", string.Empty);
After executing the above regex, nonAlphaNumericString will == "! ! ! ."
As an alternative, you can use char.IsLetterOrDigit to determine if a character is a letter or digit, then you could construct a new string without letters or digits.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
Currently I'm facing problems displaying Unicode russian characters in RichTextBox controls in .NET 1.1 Windows Forms on a German Windows 2000 (Although normal TextBox controls correctly display russian characters).
When I use this code:
byte[] rawBytes = Encoding.Default.GetBytes( rawRtf );
using ( MemoryStream ms = new MemoryStream( rawBytes ) )
{
this.LoadFile( ms, RichTextBoxStreamType.RichText );
} The output looks like this: rtf-unicode-russian-01.gif (2.6 Kb)
And when I use this code:
byte[] rawBytes = Encoding.Unicode.GetBytes( rawRtf );
using ( MemoryStream ms = new MemoryStream( rawBytes ) )
{
this.LoadFile( ms, RichTextBoxStreamType.UnicodePlainText );
} The output looks like this: rtf-unicode-russian-02.gif (2.6 Kb)
So once it correctly displays the Unicode characters but literally outputs the RTF-formattings and one time it does the other way.
Question:
Can anyone explain whether it is possible to combine RTF text and Unicode characters at the same time?
Thanks
Uwe
--
Affordable Windows-based CMS for only 99 €: try www.zeta-producer.com for free!
|
|
|
|
|
Just guessing here, but would the following work?
this.LoadFile( ms, RichTextBoxStreamType.UnicodePlainText | RichTextBoxStreamType.RichText );
I doubt that could work, since you're simultaneously specifying plain text (unicode) and rich text, which one would think is incompatible. But I might be worth a try anyways.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
Thanks for your feedback tip! I tried and although the doc of RichTextBoxStreamTypes does not show that it has the Flags attribute set, it compiles and runs without errors!
Unfortunately the results look bad, i.e. are unusable, i.e. it still renders wrong.
But thanks anyway for your time!
--
Affordable Windows-based CMS for only 99 €: try www.zeta-producer.com for free!
|
|
|
|
|
Hi!
What happens when you use Encoding.Unicode.GetBytes(); but RichTextBoxStreamType.RichText ?
The latter is a must, otherwise the RichTextBox will not evaluate the control sequences like \rtf1 and so on.
The correct Encoding for your GetBytes() call depends on the Encoding you used when you created the rawRtf .
Regards,
mav
|
|
|
|
|
mav.northwind wrote:
What happens when you use Encoding.Unicode.GetBytes(); but RichTextBoxStreamType.RichText ?
Already tried that, creates garbage.
mav.northwind wrote:
The correct Encoding for your GetBytes() call depends on the Encoding you used when you created the rawRtf.
This is a very good hint, I will look at this. Thanks!
--
Affordable Windows-based CMS for only 99 €: try www.zeta-producer.com for free!
|
|
|
|
|
Is it possible to put a "Procedure Line Separator" (line between methods) in C# / VS.NET 2003, just line with VB.NET?
I can't find the option and I think this line helps a lot. If it's not possible with VS.NET, maybe it is with an addin?
Thanks!
|
|
|
|
|
I'm making a simple application which creatres controls (labels and pictures) at runtime. When I create a new control, I add it to the Controls member of the main form. When I create two of them and drag the seccond one on the first, it hides behind it. How can I make it cover the first one? Are there any specific ControlCollection methods to to this?
|
|
|
|
|
You mean make them on same location and view them by BringToFront() method?
If so you can add them by this.Controls.AddRange(collection);
and that collectionmust contain the code that makes them at the same location .
That is if i get it ?.
|
|
|
|
|
Hello,
I hope you can help me with this issue. I am trying to build an application in C# that converts text from XML with an XSL to a HTML file and prints it according to some printersettings that can be made by an user interface. This application needs to run as an automatic process, so user intervention is not preferred.
I managed to get the XML+XSL->HTML conversion working with the following code:
public static StringWriter MergeXSL_XML(string xml, string xsl)<br />
{<br />
try<br />
{<br />
XPathDocument xPath = new XPathDocument(xml);<br />
XslTransform xTrans = new XslTransform();<br />
xTrans.Load(xsl);<br />
StringWriter strW = new StringWriter();<br />
xTrans.Transform(xPath,null,strW);<br />
strW.Close();<br />
return strW;<br />
}<br />
catch(Exception e)<br />
{<br />
MessageBox.Show(e.ToString());<br />
return null;<br />
}<br />
}<br />
The XML and XSL are read from a file or database. This is working correct. The string writer contains the information I wanted as HTML. But now the bottleneck, I cannot print the HTML.
On some sites and newsgroups people run a command through the shell that executes the printer option. But this needs a temporary file on the server, but that’s not what I want. Some also use:
<br />
wbElement.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT);<br />
But that does not give any satisfying results.
I already managed to place the HTML in the Active X component
<br />
wbCom.Navigate("about:blank");<br />
mshtml.IHTMLDocument2 hDoc = (mshtml.IHTMLDocument2)wbCom.Document; <br />
hDoc.write(html);<br />
The item shows the HMTL, but I cannot request the data later (when requesting wbCom.Document I won’t get my edited document), but that is not the real problem. The real problem is that I cannot parse the document to the printer. There is a print document method in the item:
<br />
hDoc.execCommand("Print",false,0); <br />
But calling it shortly after the placement of the HTML in the document will cause a empty document to be print out. But by pressing a button to start the print will print out a document. I already tried to insert a small sleep, but how long the sleep does not matter, an empty document will be printed.
The thing that I want is that the document can be parsed to a printable document so I can print it with the default print components of C#/.NET. Casting does not work, I tried all the IHTMLDocument* classes to find something useful, but none of them seem to have a usable function to create a printable document for the printer components in .NET. One of the casts I tried:
<br />
MessageBox.Show(hDoc.ToString());<br />
printDialog1.Document = (PrintDocument)hDoc;<br />
printDialog1.Document = (PrintDocument)hDoc;<br />
hDoc.execCommand("Print",false,0);<br />
Another problem is that it seems I cannot change the printer settings, I need to change the default printer settings in windows. For example, I need to change the paper source, I can request the sources via:
<br />
for(int i=0; i < printDocument1.PrinterSettings.PaperSources.Count; i++)<br />
{<br />
MessageBox.Show(printDocument1.PrinterSettings.PaperSources[i].ToString());<br />
}<br />
But I am not able to change them
Can someone help me with this problem?
Thanks in advance…
|
|
|
|
|
I'm trying to double buffer an entire form (i.e. all the controls into one off screen buffer). I've tried using the SetStyles double buffering but that appears to double buffer on a individual control basis and not work at all on the ListView control.
Has anyone done this before?
I'm heading in the direction of overriding OnPaint on the form itself and somehow force each control to draw into an offscreen buffer I created. When that's done draw the offscreen image on screen.
I don't have this working yet but thought I throw this out there incase someone has tried this already or has a better solution.
Thanks.
Kevin
|
|
|
|
|
try this code i got no flickering after using it (pass the function the listview handle)
public enum LVS_EX
{
LVS_EX_GRIDLINES =0x00000001,
LVS_EX_SUBITEMIMAGES =0x00000002,
LVS_EX_CHECKBOXES =0x00000004,
LVS_EX_TRACKSELECT =0x00000008,
LVS_EX_HEADERDRAGDROP =0x00000010,
LVS_EX_FULLROWSELECT =0x00000020,
LVS_EX_ONECLICKACTIVATE =0x00000040,
LVS_EX_TWOCLICKACTIVATE =0x00000080,
LVS_EX_FLATSB =0x00000100,
LVS_EX_REGIONAL =0x00000200,
LVS_EX_INFOTIP =0x00000400,
LVS_EX_UNDERLINEHOT =0x00000800,
LVS_EX_UNDERLINECOLD =0x00001000,
LVS_EX_MULTIWORKAREAS =0x00002000,
LVS_EX_LABELTIP =0x00004000,
LVS_EX_BORDERSELECT =0x00008000,
LVS_EX_DOUBLEBUFFER =0x00010000,
LVS_EX_HIDELABELS =0x00020000,
LVS_EX_SINGLEROW =0x00040000,
LVS_EX_SNAPTOGRID =0x00080000,
LVS_EX_SIMPLESELECT =0x00100000
}
public enum LVM
{
LVM_FIRST =0x1000,
LVM_SETEXTENDEDLISTVIEWSTYLE=(LVM_FIRST + 54),
LVM_GETEXTENDEDLISTVIEWSTYLE=(LVM_FIRST + 55),
}
public class Extended
{
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr handle, int messg, int wparam, int lparam);
public static void SetExStyles(IntPtr Handle)
{
LVS_EX styles;
styles = (LVS_EX)SendMessage(Handle, (int) LVM.LVM_GETEXTENDEDLISTVIEWSTYLE, 0,0);
styles |= LVS_EX.LVS_EX_DOUBLEBUFFER | LVS_EX.LVS_EX_BORDERSELECT;
SendMessage(Handle, (int) LVM.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (int) styles);
}
}
|
|
|
|
|
Hello all,
I am new to C# and trying to write a program that will strip data from three different reports (2 Excel, 1 Text), then output the three "modified" reports. I can picture the flow of the GUI, but cannot seem to grasp the capture and massaging of the data itself.
Any suggestions would be helpful
|
|
|
|
|
Welcome to c# world!
Your request is very vague. Why not ask a more specific question, like how do I open an excel document in the app? Most things you can find by doing a search of the forums, you would probable find most of the answers you are looking for.
Most here are helpful, if you have specific questions...
Some resources:
Excel: http://www.codeproject.com/csharp/csharp_excel.asp
String handling: http://www.codeproject.com/books/0735616485.asp
Hope these help.
*****************
"We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
|
|
|
|
|
I have been playing with the different events, but am not sure how to make this happen. I want to select the item currently under the mouse. This would give a highlight effect to the one you are over. Anyone know how to do this?
Thanks in advance.
*****************
"I know how hard it is for you to put food on your family." —GW
|
|
|
|
|
If you've not already found a solution, try looking at the OnMouseMove event. Are you trying to give feedback for any control on a form as the user moves from one to the other or are you trying to do this within a specific control, like a ListView or ListBox?
|
|
|
|
|
Hello everybody,
I'm building a class library and i would like to add summary information to some function/classes, the ones that are shown by the object browser. When I add the summary information it is only available to me in the object browser when I'm working in my library.
I would like to see the same information in the object browser when I add the library to an application.
Can somebody please tell me how to do that.
Regards,
Paul
|
|
|
|
|
Are you using the ///summary
in your code ,if not ,try it.
|
|
|
|
|
I'm sure, so that is not the problem
thanks anyway
|
|
|
|
|