Click here to Skip to main content
15,915,172 members
Home / Discussions / C#
   

C#

 
GeneralRe: Getting this simple crypto function to work in c#? Pin
stephen.darling9-Aug-11 12:26
stephen.darling9-Aug-11 12:26 
GeneralRe: Getting this simple crypto function to work in c#? Pin
MicroVirus9-Aug-11 12:56
MicroVirus9-Aug-11 12:56 
GeneralRe: Getting this simple crypto function to work in c#? Pin
stephen.darling9-Aug-11 13:18
stephen.darling9-Aug-11 13:18 
GeneralRe: Getting this simple crypto function to work in c#? Pin
MicroVirus9-Aug-11 13:39
MicroVirus9-Aug-11 13:39 
GeneralRe: Getting this simple crypto function to work in c#? Pin
stephen.darling9-Aug-11 13:52
stephen.darling9-Aug-11 13:52 
GeneralRe: Getting this simple crypto function to work in c#? Pin
MicroVirus9-Aug-11 14:08
MicroVirus9-Aug-11 14:08 
GeneralRe: Getting this simple crypto function to work in c#? Pin
stephen.darling9-Aug-11 14:14
stephen.darling9-Aug-11 14:14 
AnswerRe: Getting this simple crypto function to work in c#? [modified] Pin
MicroVirus10-Aug-11 2:48
MicroVirus10-Aug-11 2:48 
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.
C#
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:
C#
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

GeneralRe: Getting this simple crypto function to work in c#? Pin
stephen.darling10-Aug-11 3:57
stephen.darling10-Aug-11 3:57 
GeneralRe: Getting this simple crypto function to work in c#? Pin
BobJanova10-Aug-11 4:00
BobJanova10-Aug-11 4:00 
GeneralRe: Getting this simple crypto function to work in c#? Pin
stephen.darling10-Aug-11 4:08
stephen.darling10-Aug-11 4:08 
GeneralRe: Getting this simple crypto function to work in c#? Pin
MicroVirus10-Aug-11 4:27
MicroVirus10-Aug-11 4:27 
AnswerRe: Getting this simple crypto function to work in c#? Pin
OriginalGriff9-Aug-11 21:39
mveOriginalGriff9-Aug-11 21:39 
GeneralRe: Getting this simple crypto function to work in c#? Pin
stephen.darling10-Aug-11 4:04
stephen.darling10-Aug-11 4:04 
GeneralRe: Getting this simple crypto function to work in c#? Pin
OriginalGriff10-Aug-11 4:21
mveOriginalGriff10-Aug-11 4:21 
AnswerRe: Getting this simple crypto function to work in c#? Pin
BobJanova9-Aug-11 23:18
BobJanova9-Aug-11 23:18 
GeneralRe: Getting this simple crypto function to work in c#? Pin
stephen.darling10-Aug-11 4:19
stephen.darling10-Aug-11 4:19 
GeneralRe: Getting this simple crypto function to work in c#? Pin
BobJanova10-Aug-11 8:22
BobJanova10-Aug-11 8:22 
GeneralRe: Getting this simple crypto function to work in c#? Pin
stephen.darling11-Aug-11 4:25
stephen.darling11-Aug-11 4:25 
QuestionGet div values Pin
Herboren9-Aug-11 9:40
Herboren9-Aug-11 9:40 
AnswerRe: Get div values Pin
BobJanova9-Aug-11 23:05
BobJanova9-Aug-11 23:05 
QuestionResetting a user control using the same instance Pin
MAW309-Aug-11 9:27
MAW309-Aug-11 9:27 
AnswerRe: Resetting a user control using the same instance Pin
BillWoodruff9-Aug-11 9:58
professionalBillWoodruff9-Aug-11 9:58 
GeneralRe: Resetting a user control using the same instance Pin
MAW309-Aug-11 10:35
MAW309-Aug-11 10:35 
AnswerRe: Resetting a user control using the same instance Pin
MicroVirus9-Aug-11 12:37
MicroVirus9-Aug-11 12:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.