|
Looks like an outproc COM server. That is your programs would communicate with a .exe instead of loading a .dll.
|
|
|
|
|
><<a href=""></a>[<a href="" target="_blank"></a>]
<small></small>
|
|
|
|
|
You might want to edit your question, and look at the text: it is showing as:
><<a href=""></a>[<a href="" target="_blank"></a>]
<small></small>
Which is not particularly helpful...
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."
|
|
|
|
|
sujtha wrote:
Is there any open source library C#/C++/C which will give me the delta changes of file (it can be any type)?
Which OS are you targeting? There's a few possibilities getting .Net/rsync to play together.
GitHub has a few rsync APIs built in/for C#:
https://github.com/MatthewSteeples/rsync.net[^] (uses native System.IO)
https://github.com/kolosy/rsync.net[^] (uses pinvoke for filesystem calls)
You could also use System.Diagnostics.Process to invoke rsync and control its process from within your application. You can trap its i/o streams for analysis to get your results.
If you're looking for a C/C++ API, you could check rsync's site to see what's available, but it's going to require a Linux/Unix environment to compile and run. The Windows rsync fork comes packaged with some cygwin DLLs to meet this requirement.
|
|
|
|
|
Hello.
I have these 2 small functions that work together to decrypt a small amount of data, that is also of fixed length, a byte array of length 15;
Does anyone know if it could be re-written for c#?
I have tried a few things but to no avail, for example, I do not know what memset() does, so do not know what to do in place within c#.
I do not want to use some large crypto library, and the reason for this small function is so that the encrypted data is the exact same length of the original data, 15 bytes.
So, here is the code....and thank you.
void DecryptInstID(unsigned char *InstID)
{
unsigned char *Left, *Right;
unsigned char Aux[8];
int i, k;
Left = InstID;
Right = InstID + 8;
for (i = 0; i < 4; i++)
{
KeyedHash(Left, Aux);
for (k = 0; k < 8; k++)
Aux[k] ^= Right[k];
memcpy(Right, Left, 8);
memcpy(Left, Aux, 8);
}
}
void KeyedHash(unsigned char *Data, unsigned char *Result)
{
SHA_CTX Context;
unsigned char Digest[20];
static unsigned char Key[4] =
{
};
SHA1_Init(&Context);
SHA1_Update(&Context, Data, 8);
SHA1_Update(&Context, Key, 4);
SHA1_Final(Digest, &Context);
memcpy(Result, Digest, 8);
}
Thank you!
Regards,
Stephen
|
|
|
|
|
The .NET library has an implementation of SHA1 that you could use.
MSDN link: SHA1[^]
|
|
|
|
|
Thank you,
I was looking at that, however, I can not seem to find any way of using a key.
In the c++ code that I posted, it used SHA1 with a 4 byte key, and the decryption routine is a simple proprietry four-round feistel cipher.
I simply need to encrypt/decrypt the fixed length of bytes, without the output growing or changing in size.
The SHA1, apparantly, adds a higher level of security when used with the key.
Any Ideas?
Thank you,
Stephen
|
|
|
|
|
As far as I can understand from the code (and what I know from SHA1, which is a hashing algorithm), the actual SHA1 implementation doesn't use a key (can't use a key).
What happens in your C++ code is that you add the key as part of the 12 byte datablock-to-be-hashed: first 8 bytes of input data, then appended with a 4 byte constant key. You can just do the same in C# as you did in C++.
I admit I don't understand the actual algorithm you are using, but all you need to do is translate the code 1-to-1 from C++ to C#. The SHA1_* functions can be replaced with the SHA1 implementation (such as SHA1Managed) and the rest is almost directly valid C# code already.
About the memset function, it takes 3 parameters, memset(destination, value, countInBytes) and sets the first countInBytes bytes of destination to value.
memcpy(destination, source, count) copies count bytes from source to destination.
The algorithm itself is a bit funky with the memcpy's... It assumes a 16 byte InstID, but I guess that's alright?
|
|
|
|
|
Hi.
I have tried everything and just can't get it to work...
This is the code I have, but I am unsure how to replace the memcpy code for c#
Either way, it neither encrypts nor decrypts.
byte [] EncryptLicenseKey(byte[] licenseKey)
{
byte[] final = new byte[14];
byte[] left = new byte[14];
byte[] right = new byte[14];
byte[] Aux = new byte[14];
int i, k;
left = licenseKey;
right = licenseKey;
for (i = 0; i < 4; i++)
{
KeyedHash(left, Aux);
for (k = 0; k < 8; k++)
Aux[k] ^= right[k];
}
return Aux;
}
void KeyedHash(byte[] Data, byte[] Result)
{
byte[] Key = {0xff, 0xff, 0xff, 0xff};
HMACSHA1 mac = new HMACSHA1(Key);
Result = mac.ComputeHash(Data);
}
Still just trying to be able to pass a fixed length byte array and encrypt/decrypt it so that the output is EXACTLY the same length as the data we passed in, and use the key...
If you can help any further I will be very happy indeed
Thank you very much,
Regards,
Stephen
|
|
|
|
|
Sorry, I had forgotten for a second that C# doesn't support pointers anymore (at least, not 'normally' - only in unmanaged cases can you still use them).
I don't have the IDE in front of me at the moment, but I think this should work: the pointers are replaced by indices and the memcpy's are replaced by Array<byte>.Copy.
void DecryptInstID(byte[] InstID)
{
byte[] Aux = new byte[8];
int i, k;
for (i = 0; i < 4; i++)
{
KeyedHash(InstID, Aux);
for (k = 0; k < 8; k++)
Aux[k] ^= InstID[k + 8];
byte[].Copy(InstID, 0, InstID, 8, 8);
byte[].Copy(Aux, InstID, 8);
}
}
|
|
|
|
|
Thank you for taking the time to write some code, however...
MicroVirus wrote: byte[].Copy(InstID, 0, InstID, 8, 8);
byte[].Copy(Aux, InstID, 8);
I get an error telling me that "Invalid expression term byte" and the [] is highlighted as causing the error?
Thank you,
Stephen
|
|
|
|
|
Hmmm, yeah I was doubting about that :P Replace byte[] with Array<byte> and that should fix it, I think.
|
|
|
|
|
Hi.
Instead I used the following, and that worked...
System.Array.Copy(licenseKey, 0, licenseKey, 8, 8);
But the code still wont work, and I get an out of bounds/index error from this line:
Aux[k] ^= right[k + 8];
I know that in the c++ version, the original data and the encrypted data are exactly the same length, and when I used the other function it worked OK. So I can only presume it is trying to grow the original data array, which I would not want.
So, I am still stuck with this one and it is driving me insane.
Thank you for your help so far though, it is appreciated!
Steve
|
|
|
|
|
Sorry about the confusion with byte[]/Array. Like I said, I was having to go without IDE at the time and couldn't remember how it was in C# exactly.
The line you point to where you get an index out of bounds error does not appear anywhere in the code I gave. Please use what I supplied, or if it's not working let's go from there.
void DecryptInstID(byte[] InstID)
{
byte[] Aux = new byte[8];
int i, k;
for (i = 0; i < 4; i++)
{
KeyedHash(InstID, out Aux);
for (k = 0; k < 8; k++)
Aux[k] ^= InstID[k + 8];
Array.Copy(InstID, 0, InstID, 8, 8);
Array.Copy(Aux, InstID, 8);
}
}
Now for this to work, your going to have to pass in for InstID a 16 byte array (just like it was in the C++ code; you said 15 bytes, but the C++ code suggests/needs 16 bytes).
EDIT: I was just thinking about the KeyedHash you are using. You should use the overload of ComputeHash that accepts start and size: HMACSHA1.ComputeHash(data, 0, 8) to only hash the first 8 bytes of the data supplied, as it was with your C++ code. Currently, your keyed hash function hashes the entire 16 byte (or so) block, rather than only the first 8 bytes as intended.
So:
void KeyedHash(byte[] data, out byte[] result)
{
System.Security.Cryptography.HMACSHA1 mac = new System.Security.Cryptography.HMACSHA1(yourKeyHere);
result = mac.ComputeHash(data, 0, 8);
}
modified on Wednesday, August 10, 2011 9:11 AM
|
|
|
|
|
Hi,
Thank you once again for the code, I have just a couple more questions if I may?
MicroVirus wrote: you said 15 bytes, but the C++ code suggests/needs 16 bytes)
Yes, and when I corrected that it worked. However, in my own code I modified InstID to be a lower amount of bytes. Where in this code do I edit it so that it can do the same, but with less bytes?
Also, When I pass the encypted value back through the function, it does not decrypt to the original data.
I was under the impresion that using a 4 round feistal cypher like this was simply the same function for both encryption and decryption?
Thank you again,
Stephen
|
|
|
|
|
You're mixing in a hash (and only a part of the hash at that). I don't see how this is ever going to be reversible. Do you have round-tripping working in C++ with this algorithm?
|
|
|
|
|
Hi,
The formula the code is based on is:
Left = Right ^ First-8 (SHA-1 (Left + Key))
Right = Left
Now, in the code and text I have, it is quite confident that this is reversable, although I am now doubting it, however, I have seen a simular function that combined part of a hash and was reversable,although I do not know if the "reverse" function or "Encryption" routine must be different, as I only have the code for this "decritption" code.
Kind Regards,
Stephen
|
|
|
|
|
stephen.darling wrote: Yes, and when I corrected that it worked. However, in my own code I modified InstID to be a lower amount of bytes. Where in this code do I edit it so that it can do the same, but with less bytes?
The code given is an exact translation of the C++ code. Can the C++ code do with less bytes? In that case the C# can too, though you're going to have to modify both the C++ code and the C# code to manage that.
I don't understand the algorithm and the other people that have replied to this thread also don't know if this'll work or not. That means all I have to go on is the original C++ code. From that, we can infer that the InstID contains a 16 byte 'encrypted' sequence and is then 'decrypted' in-place (with a small Aux buffer of 8 bytes) to a 16 byte sequence.
Like asked before, does the C++ code work in encrypting/decrypting and does it use the same function for both? I tested the C# code and it is not capable of using the same function for both encryption and decryption.
|
|
|
|
|
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
|
|
|
|
|