Click here to Skip to main content
15,891,248 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionRegarding Ado.net Pin
Member 111616251-Dec-14 17:28
Member 111616251-Dec-14 17:28 
AnswerRe: Regarding Ado.net Pin
PIEBALDconsult1-Dec-14 18:07
mvePIEBALDconsult1-Dec-14 18:07 
SuggestionRe: Regarding Ado.net Pin
Richard Deeming2-Dec-14 2:34
mveRichard Deeming2-Dec-14 2:34 
QuestionRe: Regarding Ado.net Pin
ZurdoDev2-Dec-14 2:39
professionalZurdoDev2-Dec-14 2:39 
AnswerRe: Regarding Ado.net Pin
Member 111616252-Dec-14 3:25
Member 111616252-Dec-14 3:25 
AnswerRe: Regarding Ado.net Pin
ZurdoDev2-Dec-14 3:28
professionalZurdoDev2-Dec-14 3:28 
QuestionMVVM Code First Validate error Pin
Paolo Mazzon30-Nov-14 11:32
Paolo Mazzon30-Nov-14 11:32 
Questionsha1 function giving a different result to equivalent .net code Pin
JMK-NI26-Nov-14 10:21
professionalJMK-NI26-Nov-14 10:21 
I have the following PHP code:

PHP
$stringToHash = "10123456789"."2014:11:25-15:42:00"."20.00"."826"."sharedsecret";

echo($stringToHash);
// outputs:
// 101234567892014:11:25-15:42:0020.00826sharedsecret

$ascii = bin2hex($stringToHash);

echo($ascii);
// outputs:   
// 3130313233343536373839323031343a31313a32352d31353a34323a303032302e3030383236736861726564736563726574

$sha = sha1($ascii);

echo($sha);
// outputs:
// 847aa9da32c54ed8bb9183007336f5762a62ef20


Here is the equivalent C# code:

C#
var stringToHash = "10123456789" + "2014:11:25-15:42:00" + "20.00" + "826" + "sharedsecret";

Console.WriteLine(stringToHash);
// outputs:
// 101234567892014:11:25-15:42:0020.00826sharedsecret

var bytes = Encoding.ASCII.GetBytes(stringToHash);

var hexString = BitConverter.ToString(bytes).Replace("-", string.Empty);

Console.WriteLine(hexString);
// outputs:
// 3130313233343536373839323031343A31313A32352D31353A34323A303032302E3030383236736861726564736563726574

SHA1 sha = new SHA1CryptoServiceProvider();
var password = sha.ComputeHash(bytes);
var result = BitConverter.ToString(password).ToLower().Replace("-", string.Empty);

Console.WriteLine(result);
// outputs:
// c8069048623d6b98a08454e43e1a02a42cf7d61d

var hexStringBytes = Encoding.ASCII.GetBytes(hexString);
var hexStringPassword = sha.ComputeHash(hexStringBytes);
var hexStringResult = BitConverter.ToString(hexStringPassword).ToLower().Replace("-", string.Empty);

Console.WriteLine(hexStringResult);
// outputs:
// bd857ca08446001f7182fbbbd41e747abe302a87


The first two outputs are the same. The original strings are identical, as are the ASCII hex arrays after conversion, but sha1() in PHP is giving me a different outcome to .net's SHA1CryptoServiceProvider. If I convert that output to a string and hash it again, the result is also different.

In .net, an object has to be in the form of a byte array before you can create an SHA hash from it, and I don't understand what I need to convert to the byte array to produce the same output as the PHP code.

This is problematic as the third party service I am posting to uses the PHP version to verify an object on their end, and my program is written in .net. I could write a middle-man in PHP and relay through that, but I really don't want have to do that.

Any insight into why the two are giving different results? Thanks
AnswerRe: sha1 function giving a different result to equivalent .net code Pin
Richard Deeming26-Nov-14 10:45
mveRichard Deeming26-Nov-14 10:45 
QuestionProblem Saving Data Pin
Paolo Mazzon21-Nov-14 18:54
Paolo Mazzon21-Nov-14 18:54 
AnswerRe: Problem Saving Data Pin
Richard MacCutchan21-Nov-14 21:23
mveRichard MacCutchan21-Nov-14 21:23 
AnswerRe: Problem Saving Data Pin
den2k8822-Nov-14 1:48
professionalden2k8822-Nov-14 1:48 
GeneralRe: Problem Saving Data Pin
Richard MacCutchan22-Nov-14 2:46
mveRichard MacCutchan22-Nov-14 2:46 
GeneralRe: Problem Saving Data Pin
den2k8822-Nov-14 2:58
professionalden2k8822-Nov-14 2:58 
GeneralRe: Problem Saving Data Pin
Richard MacCutchan22-Nov-14 3:09
mveRichard MacCutchan22-Nov-14 3:09 
AnswerRe: Problem Saving Data Pin
Paolo Mazzon22-Nov-14 6:24
Paolo Mazzon22-Nov-14 6:24 
GeneralRe: Problem Saving Data Pin
Paolo Mazzon22-Nov-14 19:05
Paolo Mazzon22-Nov-14 19:05 
Questionhow do I uncheck a list box in vb.net Pin
ceewhitehead21-Nov-14 3:13
ceewhitehead21-Nov-14 3:13 
AnswerRe: how do I uncheck a list box in vb.net Pin
ceewhitehead21-Nov-14 6:13
ceewhitehead21-Nov-14 6:13 
SuggestionRe: how do I uncheck a list box in vb.net Pin
Richard Deeming24-Nov-14 2:27
mveRichard Deeming24-Nov-14 2:27 
QuestionPrimary Bugs and Unit Testing Pin
Laiju k11-Nov-14 17:20
professionalLaiju k11-Nov-14 17:20 
AnswerRe: Primary Bugs and Unit Testing Pin
Pete O'Hanlon11-Nov-14 20:32
mvePete O'Hanlon11-Nov-14 20:32 
GeneralRe: Primary Bugs and Unit Testing Pin
Laiju k11-Nov-14 21:30
professionalLaiju k11-Nov-14 21:30 
AnswerRe: Primary Bugs and Unit Testing Pin
Bernhard Hiller11-Nov-14 21:38
Bernhard Hiller11-Nov-14 21:38 
GeneralRe: Primary Bugs and Unit Testing Pin
Laiju k11-Nov-14 22:00
professionalLaiju k11-Nov-14 22:00 

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.