Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - Truncating a byte array vs. substringing the Encoded string coming out of SHA-256 -


i not familiar hashing algorithms , risks associated when using them , therefore have question on answer below received on previous question . . .

based on comment hash value must, when encoded ascii, fit within 16 asci characters, solution first, choose cryptographic hash function (the sha-2 family includes sha-256, sha-384, , sha-512) then, truncate output of chosen hash function 96 bits (12 bytes) - is, keep first 12 bytes of hash function output , discard remaining bytes then, base-64-encode truncated output 16 ascii characters (128 bits) yielding 96-bit-strong cryptographic hash.

if substring base-64-encoded string 16 characters fundamentally different keeping first 12 bytes of hash function , base-64-encoding them? if so, please explain (provide example code) truncating byte array?

i tested substring of full hash value against 36,000+ distinct values , had no collisions. code below current implementation.

thanks (and clarity) can provide.

public static byte[] createsha256hash(string data) {     byte[] datatohash = (new unicodeencoding()).getbytes(data);     sha256 sham = new sha256managed();     byte[] hasheddata = sham.computehash(datatohash);      return hasheddata; }  public override void inputbuffer_processinputrow(inputbufferbuffer row) {     byte[] hasheddata = createsha256hash(row.hashstring);      string s = convert.tobase64string(hasheddata, base64formattingoptions.none);      row.hashvalue = s.substring(0, 16);   } 

[original post] (http://stackoverflow.com/questions/4340471/is-there-a-hash-algorithm-that-produces-a-hash-size-of-64-bits-in-c)

no, there no difference. however, it's easier base64 string of first 12 bytes of array, instead of truncating array:

public override void inputbuffer_processinputrow(inputbufferbuffer row) {      byte[] hasheddata = createsha256hash(row.hashstring);      row.hashvalue = convert.tobase64string(hasheddata, 0, 12);  } 

the base 64 encoding puts 6 bits in each character, 3 bytes (24 bits) goes 4 characters. long splitting data @ 3 byte boundary, it's same splitting string @ 4 character boundary.

if try split data between these boundaries, base64 string padded filler data next boundary, result not same.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -