|
so why can't you explain a little of that?
share that little of knoladge I need to get things starting... I'm corrently stuck in my project just because of this.
|
|
|
|
|
It's not that I dont want to explain it, it means it's going to take long. I have uploaded my experiments to ftp://ftp.uunet.co.za/pub/incoming/CryptoTests.zip (and no clickety, use a decent FTP client or DL manager).
|
|
|
|
|
Here's something that should help:
<FONT color=Blue>public abstract class</FONT> GenericTransform : SymmetricAlgorithm, ICryptoTransform
{
<FONT color=Blue>static readonly</FONT> RandomNumberGenerator RANDOM = RandomNumberGenerator<FONT color=DarkBlue>.</FONT>Create<FONT color=DarkBlue>()</FONT>;
<FONT color=Blue>static readonly</FONT> HashAlgorithm HASH = HashAlgorithm<FONT color=DarkBlue>.</FONT>Create<FONT color=DarkBlue>()</FONT>;
TransformMode curmode = TransformMode<FONT color=DarkBlue>.</FONT>None;
<FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> initial_iv;
<FONT color=Blue>protected enum</FONT> TransformMode
{
None, Encrypt, Decrypt
}
<FONT color=Blue>protected</FONT> TransformMode CurrentMode
{
<FONT color=Blue>get</FONT> {<FONT color=Blue>return</FONT> curmode;}
<FONT color=Blue>set</FONT> {curmode = <FONT color=Blue>value</FONT>;}
}
<FONT color=Blue>protected</FONT> GenericTransform<FONT color=DarkBlue>()</FONT>
{
<FONT color=DarkGreen>
BlockSizeValue = <FONT color=Red>64</FONT>;
KeySizeValue = <FONT color=Red>128</FONT>;
PaddingValue = PaddingMode<FONT color=DarkBlue>.</FONT>PKCS7;
LegalKeySizesValue = <FONT color=Blue>new</FONT> KeySizes<FONT color=DarkBlue>[]</FONT>{ <FONT color=Blue>new</FONT> KeySizes<FONT color=DarkBlue>(</FONT>KeySizeValue,KeySizeValue,<FONT color=Red>0</FONT><FONT color=DarkBlue>)</FONT> };
LegalBlockSizesValue = <FONT color=Blue>new</FONT> KeySizes<FONT color=DarkBlue>[]</FONT>{ <FONT color=Blue>new</FONT> KeySizes<FONT color=DarkBlue>(</FONT>BlockSizeValue,BlockSizeValue,<FONT color=Red>0</FONT><FONT color=DarkBlue>)</FONT> };
}
<FONT color=DarkGreen>
<FONT color=Blue>int</FONT> ICryptoTransform<FONT color=DarkBlue>.</FONT>InputBlockSize
{
<FONT color=Blue>get</FONT> { <FONT color=Blue>return</FONT> BlockSizeValue/<FONT color=Red>8</FONT>; }
}
<FONT color=DarkGreen>
<FONT color=Blue>public abstract int</FONT> OutputBlockSize {<FONT color=Blue>get</FONT>;}
<FONT color=Blue>public abstract int</FONT> TransformBlock<FONT color=DarkBlue>(</FONT><FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> inputBuffer, <FONT color=Blue>int</FONT> inputOffset, <FONT color=Blue>int</FONT> inputCount, <FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> outputBuffer, <FONT color=Blue>int</FONT> outputOffset<FONT color=DarkBlue>)</FONT>;
<FONT color=Blue>public byte</FONT><FONT color=DarkBlue>[]</FONT> TransformFinalBlock<FONT color=DarkBlue>(</FONT><FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> inputBuffer, <FONT color=Blue>int</FONT> inputOffset, <FONT color=Blue>int</FONT> inputCount<FONT color=DarkBlue>)</FONT>
{
<FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> outputBuffer = <FONT color=Blue>null</FONT>;
<FONT color=Blue>bool</FONT> enc = curmode <FONT color=DarkBlue>==</FONT> TransformMode<FONT color=DarkBlue>.</FONT>Encrypt;
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>PaddingValue <FONT color=DarkBlue>==</FONT> PaddingMode<FONT color=DarkBlue>.</FONT>None<FONT color=DarkBlue>)</FONT>
{
outputBuffer = <FONT color=Blue>new byte</FONT>[inputCount];
}
<FONT color=Blue>else</FONT>
{
outputBuffer = <FONT color=Blue>new byte</FONT>[OutputBlockSize];
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>enc<FONT color=DarkBlue>)</FONT>
{
<FONT color=DarkGreen>
<FONT color=Blue>byte</FONT> pad = <FONT color=DarkBlue>(</FONT><FONT color=Blue>byte</FONT><FONT color=DarkBlue>)(</FONT>OutputBlockSize - inputCount<FONT color=DarkBlue>)</FONT>;
<FONT color=Blue>for</FONT> <FONT color=DarkBlue>(</FONT><FONT color=Blue>int</FONT> i = inputCount; i < OutputBlockSize; i<FONT color=DarkBlue>++)</FONT>
{
inputBuffer[i] = <FONT color=DarkBlue>(</FONT>PaddingValue <FONT color=DarkBlue>==</FONT> PaddingMode<FONT color=DarkBlue>.</FONT>PKCS7 ? pad : <FONT color=DarkBlue>(</FONT><FONT color=Blue>byte</FONT><FONT color=DarkBlue>)</FONT><FONT color=Red>0</FONT><FONT color=DarkBlue>)</FONT>;
}
}
}
<FONT color=Blue>int</FONT> c = TransformBlock<FONT color=DarkBlue>(</FONT>inputBuffer, inputOffset, outputBuffer<FONT color=DarkBlue>.</FONT>Length, outputBuffer, <FONT color=Red>0</FONT><FONT color=DarkBlue>)</FONT>;
<FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> final = <FONT color=Blue>null</FONT>;
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>PaddingValue <FONT color=DarkBlue>==</FONT> PaddingMode<FONT color=DarkBlue>.</FONT>None<FONT color=DarkBlue>)</FONT>
{
final = <FONT color=Blue>new byte</FONT>[inputCount];
}
<FONT color=Blue>else</FONT>
{
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>enc<FONT color=DarkBlue>)</FONT>
{
final = <FONT color=Blue>new byte</FONT>[OutputBlockSize];
}
<FONT color=Blue>else</FONT>
{
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>inputCount <FONT color=DarkBlue>==</FONT> <FONT color=Red>0</FONT><FONT color=DarkBlue>)</FONT>
{
final = <FONT color=Blue>new byte</FONT>[<FONT color=Red>0</FONT>];
}
<FONT color=Blue>else</FONT>
{
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>PaddingValue <FONT color=DarkBlue>==</FONT> PaddingMode<FONT color=DarkBlue>.</FONT>Zeros<FONT color=DarkBlue>)</FONT>
{
<FONT color=Blue>for</FONT> <FONT color=DarkBlue>(</FONT><FONT color=Blue>int</FONT> i = outputBuffer<FONT color=DarkBlue>.</FONT>Length - <FONT color=Red>1</FONT>; i <FONT color=DarkBlue>>=</FONT> <FONT color=Red>0</FONT>; i<FONT color=DarkBlue>--)</FONT>
{
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>outputBuffer[i] <FONT color=DarkBlue>!=</FONT> <FONT color=Red>0</FONT><FONT color=DarkBlue>)</FONT>
{
final = <FONT color=Blue>new byte</FONT>[i + <FONT color=Red>1</FONT>];
<FONT color=Blue>break</FONT>;
}
}
}
<FONT color=Blue>else</FONT>
{
<FONT color=Blue>byte</FONT> pk = outputBuffer[outputBuffer<FONT color=DarkBlue>.</FONT>Length - <FONT color=Red>1</FONT>];
<FONT color=Blue>for</FONT> <FONT color=DarkBlue>(</FONT><FONT color=Blue>int</FONT> i = outputBuffer<FONT color=DarkBlue>.</FONT>Length - <FONT color=Red>1</FONT>; <FONT color=DarkBlue>(</FONT>i <FONT color=DarkBlue>>=</FONT> outputBuffer<FONT color=DarkBlue>.</FONT>Length - <FONT color=Red>1</FONT> - pk<FONT color=DarkBlue>)</FONT>; i<FONT color=DarkBlue>--)</FONT>
{
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>outputBuffer[i] <FONT color=DarkBlue>!=</FONT> pk<FONT color=DarkBlue>)</FONT>
{
final = <FONT color=Blue>new byte</FONT>[i + <FONT color=Red>1</FONT>];
<FONT color=Blue>break</FONT>;
}
}
}
}
}
}
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>final <FONT color=DarkBlue>==</FONT> <FONT color=Blue>null</FONT><FONT color=DarkBlue>)</FONT>
{
final = <FONT color=Blue>new byte</FONT>[outputBuffer<FONT color=DarkBlue>.</FONT>Length];
}
Buffer<FONT color=DarkBlue>.</FONT>BlockCopy<FONT color=DarkBlue>(</FONT>outputBuffer, inputOffset, final, <FONT color=Red>0</FONT>, final<FONT color=DarkBlue>.</FONT>Length<FONT color=DarkBlue>)</FONT>;
IVValue = initial_iv;
<FONT color=Blue>return</FONT> final;
}
<FONT color=Blue>public sealed override</FONT> ICryptoTransform CreateDecryptor<FONT color=DarkBlue>(</FONT><FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> rgbKey, <FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> rgbIV<FONT color=DarkBlue>)</FONT>
{
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>rgbKey <FONT color=DarkBlue>!=</FONT> <FONT color=Blue>null</FONT><FONT color=DarkBlue>)</FONT>
{
Key = rgbKey;
}
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>rgbIV <FONT color=DarkBlue>!=</FONT> <FONT color=Blue>null</FONT><FONT color=DarkBlue>)</FONT>
{
IV = rgbIV;
}
curmode = TransformMode<FONT color=DarkBlue>.</FONT>Decrypt;
<FONT color=Blue>return this</FONT>;
}
<FONT color=Blue>public sealed override</FONT> ICryptoTransform CreateEncryptor<FONT color=DarkBlue>(</FONT><FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> rgbKey, <FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> rgbIV<FONT color=DarkBlue>)</FONT>
{
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>rgbKey <FONT color=DarkBlue>!=</FONT> <FONT color=Blue>null</FONT><FONT color=DarkBlue>)</FONT>
{
Key = rgbKey;
}
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>rgbIV <FONT color=DarkBlue>!=</FONT> <FONT color=Blue>null</FONT><FONT color=DarkBlue>)</FONT>
{
IV = rgbIV;
}
curmode = TransformMode<FONT color=DarkBlue>.</FONT>Encrypt;
<FONT color=Blue>return this</FONT>;
}
<FONT color=Blue>public sealed override void</FONT> GenerateIV<FONT color=DarkBlue>()</FONT>
{
IVValue = <FONT color=Blue>new byte</FONT>[BlockSizeValue/<FONT color=Red>8</FONT>];
<FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> h = HASH<FONT color=DarkBlue>.</FONT>ComputeHash<FONT color=DarkBlue>(</FONT>Key<FONT color=DarkBlue>)</FONT>;
Buffer<FONT color=DarkBlue>.</FONT>BlockCopy<FONT color=DarkBlue>(</FONT>h,<FONT color=Red>0</FONT>,IVValue,<FONT color=Red>0</FONT>, IVValue<FONT color=DarkBlue>.</FONT>Length<FONT color=DarkBlue>)</FONT>;
}
<FONT color=Blue>public sealed override void</FONT> GenerateKey<FONT color=DarkBlue>()</FONT>
{
KeyValue = <FONT color=Blue>new byte</FONT>[KeySizeValue/<FONT color=Red>8</FONT>];
RANDOM<FONT color=DarkBlue>.</FONT>GetNonZeroBytes<FONT color=DarkBlue>(</FONT>KeyValue<FONT color=DarkBlue>)</FONT>;
}
<FONT color=Blue>public override byte</FONT><FONT color=DarkBlue>[]</FONT> IV
{
<FONT color=Blue>get</FONT>
{
<FONT color=Blue>return base</FONT><FONT color=DarkBlue>.</FONT>IV;
}
<FONT color=Blue>set</FONT>
{
<FONT color=Blue>base</FONT><FONT color=DarkBlue>.</FONT>IV = <FONT color=Blue>value</FONT>;
initial_iv = IVValue<FONT color=DarkBlue>.</FONT>Clone<FONT color=DarkBlue>()</FONT> <FONT color=Blue>as byte</FONT><FONT color=DarkBlue>[]</FONT>;
}
}
<FONT color=Blue>public virtual bool</FONT> CanReuseTransform
{
<FONT color=Blue>get</FONT> {<FONT color=Blue>return false</FONT>;}
}
<FONT color=Blue>public virtual bool</FONT> CanTransformMultipleBlocks
{
<FONT color=Blue>get</FONT> { <FONT color=Blue>return false</FONT>; }
}
<FONT color=Blue>static string</FONT> ByteAsString<FONT color=DarkBlue>(</FONT><FONT color=Blue>byte</FONT><FONT color=DarkBlue>[]</FONT> input<FONT color=DarkBlue>)</FONT>
{
<FONT color=Blue>string</FONT> output = <FONT color=Maroon>""</FONT>;
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>input <FONT color=DarkBlue>!=</FONT> <FONT color=Blue>null</FONT><FONT color=DarkBlue>)</FONT>
{
<FONT color=Blue>foreach</FONT> <FONT color=DarkBlue>(</FONT><FONT color=Blue>byte</FONT> b <FONT color=Blue>in</FONT> input<FONT color=DarkBlue>)</FONT>
{
output <FONT color=DarkBlue>+=</FONT> b<FONT color=DarkBlue>.</FONT>ToString<FONT color=DarkBlue>(</FONT><FONT color=Maroon>"X2"</FONT><FONT color=DarkBlue>)</FONT>;
}
}
<FONT color=Blue>else</FONT>
{
output = <FONT color=Maroon>"NULL"</FONT>;
}
<FONT color=Blue>return</FONT> output;
}
<FONT color=Blue>public sealed override string</FONT> ToString<FONT color=DarkBlue>()</FONT>
{
<FONT color=Blue>if</FONT> <FONT color=DarkBlue>(</FONT>Debugger<FONT color=DarkBlue>.</FONT>IsAttached<FONT color=DarkBlue>)</FONT>
{
<FONT color=Blue>return string</FONT><FONT color=DarkBlue>.</FONT>Format<FONT color=DarkBlue>(</FONT><FONT color=Maroon>"{0}(KEY({3}) = {1},\nIV({4}) = {2})"</FONT>, GetType<FONT color=DarkBlue>().</FONT>Name,
ByteAsString<FONT color=DarkBlue>(</FONT>KeyValue<FONT color=DarkBlue>)</FONT>, ByteAsString<FONT color=DarkBlue>(</FONT>IVValue<FONT color=DarkBlue>)</FONT>, KeySize, BlockSize<FONT color=DarkBlue>)</FONT>;
}
<FONT color=Blue>else</FONT>
{
<FONT color=Blue>return base</FONT><FONT color=DarkBlue>.</FONT>ToString<FONT color=DarkBlue>()</FONT>;
}
}
}
|
|
|
|
|
Well done leppie, nice class.
If he had difficulty with the docs hes gonna have hours of fun with that;)
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
Hi,
I've read your thread. I agree that sometimes it's frustrating not to get the answers you'ld like, but if Cpians don't know the answer, they can't give it to you.
Regarding your question. If I understood correctly you want to write your own encryption tool?
Encryption is actually nothing more then mathematics. If you can find out how the mathematics is applied in encryption you would be able to encrypt/decrypt files/strings/...
I have written (a very, very) simple encryption tool for strings a while back. I don't know if it can help you. (if you think it would, I can send it to you)
My suggestion would be that you look up the mathematics you need and start from there.
Good luck with your problem!
Coulda, woulda, shoulda doesn't matter if you don't.
<marquee>
|
|
|
|
|
I already built my encryption mathematics\algorythem all I need is the info on the parameters of the ICryptoTransform interface members implements.
you just didn't understand what is going on here.
|
|
|
|
|
NaNg15241 wrote: and I will keep posting it every time it crosses the next page untill I will have answers, and as you see.... this is REALY ORGENT!
This sounds like you are trying to hold us to ransom, and doing this is likely to get you ignored!
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
but there is a fact that there are more then 8 msgs that is not mine in this thread. :P
|
|
|
|
|
I said likely, not definately!
Listen, Ive taken a look at all your threads that you've posted here, and you seem like a polite enough kid who's just eager to learn...which is a good start. However, bully tactics like "ill post this every day until it gets answered" will end up annoying people.
Let me give you some advice, start by reading the thread stuck to the top titled "How to get answers to your questions". Note that it says that for coding questions you should post the relevant code you are using. Nobody can help you with a coding question without it.
That said, you are asking about a very specific corner of the framework that not everyone deals with. Even in a community as large as CP there will be few people that really know this well. What this means is that if YOU want to learn this corner of the framework you'll have to spend days, and maybe even weeks reading, trying and understanding the crypto classes. Nobody can hand you this knowledge within one simple post.
Good luck, and your enthusiasm for answering other people's questions has not gone unnoticed I promise!
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
Nice... 5! And I am framing it as well
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Hate to ask such a simple question. A dll returns an object to me:
rtable
{System.Array}
[0]: {99.3046875}
[1]: {99.3046875}
[2]: {0.0}
[3]: {0.0}
[4]: "912828FD71"
[5]: ""
[6]: {0}
[7]: ""
[8]: ""
[9]: ""
[10]: {0.0}
[11]: ""
[12]: "1-Jan-1970 00:00:00"
[13]: ""
How can I access these elements? This doesn't work:
rtable[0]
error: object 'rtable' doesn't have an indexer
Thx.
|
|
|
|
|
if it is a collection (i asume it is) search for the methods of it like movenext (increments the position of the collection to the next item) etc...
|
|
|
|
|
Array.GetValue Method[^] should be the hero that saves your day
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
got it, had to recast as (object [])object.
then I have an enumerator.
|
|
|
|
|
Hi.
How can i add IE component to my project?
There isn't it in toolbox !
I use VS 2005.
Best wishes
|
|
|
|
|
System.Windows.Forms.WebBrowser
I don't remember if it on the toolbox by default. If not right click the toolbox and select the "Choose Item" context menu then follow directions.
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
hi friends,
is there possiblity to record sound stream i.e. if i am running some music via media player or winamp.
can i record that stream and store in mp3 or any other format using c#?
Naveed Kamboh
-- modified at 11:17 Friday 12th May, 2006
|
|
|
|
|
hello there
I want to add virtual printer to my system . and when any system user print the document. my application should recieve the bytes or what ever is sent by the application.
Any help would be highly appreicated
Best Regards
Rizwan Bashir
|
|
|
|
|
I want to check for a decimal number where one or more digits are allowed before the decimal point (in which case digits after the decimal point are optional) or one or more characters are allowed after the decimal point (in which case digits before the decimal point are optional). The decimal point is optional, but you cannot have just the decimal point.
e.g. 1.3, 1., .1 all ok.
. not ok.
The pattern @"^\d+\.?\d*$" takes care of the case where there are digits before the decimal point.
The pattern @"^\d*\.?\d+$" takes care of the case where there are digits after the decimal point.
Either one by itself is not sufficient.
I thought I could combine them to have an either/or expression the way you would have [a|n] to say either 'a' or 'n', by making them subexpressions like this:
@"[(^\d+\.?\d*$) | (\d*\.?\d+$)]"
It doesn't work, though. This matches on each digit and the decimal point. e.g., 30.5 give 4 matches - '3', '0', '.', '5'.
I can achieve what I want in other ways, but wondering if someone can tell me if there is a regular expression to do what I want and/or explain why the last pattern matches on each digit - I'm not seeing it.
Thanks.
|
|
|
|
|
hi all,
this image (http://img227.imageshack.us/img227/6070/notifyicon6kk.jpg) shows msn messenger contextmenu and my form's contextmenu.
the problem is: the options (Restore, Exit ... etc) are approximately in the middle of contextmenu when compared with msn's.
how can i align them (Restore, Exit options...) leftest part of contextmenu ¿
i couldnt change the padding from properties
help please ...
|
|
|
|
|
contextmenuitem.TextAlign - this is the property... search for what you need... I think it's middle right
|
|
|
|
|
How do I exit multiple, nested, methods when a condition is true?
For example, an event is invoked, then when x = 0, stop activity
<br />
void event1(...) {<br />
method1()<br />
}<br />
<br />
public void method1() {<br />
method2();<br />
}<br />
<br />
public void method2() {<br />
method3();<br />
}<br />
<br />
public void method3() {<br />
if (x == 0) {<br />
}<br />
}<br />
<br />
If x = 0, the "more stuff" should never be done.
I know I can exit each separately, but I would have to test x each time.
Thanks for any help.
bigiorno
|
|
|
|
|
void event1(...) {
if (method1())
{
}
}
public bool method1() {
if (!method2()) return false;
return true;
}
public bool method2() {
if (!method3()) return false;
return true;
}
public bool method3() {
if (x == 0) {
return false;
}
return true;
}
|
|
|
|
|
You could use a return code instead of using 'void' everywhere.
The return code would indicate if the method succeeded...
Your code would become:
void event1(...) {
if (method1())
{
}
}
public bool method1() {
if (method2())
{
return true;
}
return false;
}
public bool method2() {
if (method3())
{
return true;
}
return false;
}
public bool method3() {
if (x == 0) {
return false;
}
return true;
} another way would be to use exceptions which would make your code look like:
void event1(...) {
try {
method1();
}
catch (Exception e) {
}
}
public void method1() {
method2();
}
public void method2() {
method3();
}
public void method3() {
if (x == 0) {
Exception e;
throw e;
}
} Hope this helps...
RicoH
Don't think you are, know you are...
custom hardware & software - olloc.be
|
|
|
|
|
Do not work MVR 1000 sx(Canopus) with DirectX.Capture. Somebody know what's problem?
Sorry, my English badly.
|
|
|
|