.net - DSACryptoServiceProvider.ImportParameters 'Bad Data' -


i'm testing dsacryptoserviceprovider using parameters given in fips pub 186.

when attempt import public key parameters, receive 'bad data' error:

dim pstring string = "08df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80291" dim qstring string = "0c773218c737ec8ee993b4f2ded30f48edace915f" dim gstring string = "0626d027839ea0a13413163a55b4cb500299d5522956cefcb3bff10f399ce2c2e71cb9de5fa24babf58e5b79521925c9cc42e9f6f464b088cc572af53e6d78802" dim ystring string = "019131871d75b1612a819f29d78d1b0d7346f7aa77bb62a859bfd6c5675da9d212d3a36ef1672ef660b8c7c255cc0ec74858fba33f44c06699630a76b030ee333" dim seedstring string = "0d5014e4b60ef2ba8b6211b4062ba3224e0427dd3"  dim p biginteger = getbiginteger(pstring) dim q biginteger = getbiginteger(qstring) dim g biginteger = getbiginteger(gstring) dim y biginteger = getbiginteger(ystring) dim seed biginteger = getbiginteger(seedstring)  dim dp new dsaparameters dp.p = getbytes(p,64) dp.q = getbytes(q,20) dp.g = getbytes(g,64) dp.y = getbytes(y,64) dp.counter = 105 dp.seed = getbytes(seed,20)  using dcsp new dsacryptoserviceprovider(512)   dcsp.importparameters(dp) ' results in 'bad data' end using 

.

function getbiginteger(hexstring string) biginteger   return biginteger.parse(hexstring, numberstyles.hexnumber) end function 

.

function getbytes(bi biginteger,length int32) byte()   dim bytes() byte = bi.tobytearray   if bytes.length > length     dim result(length - 1) byte     array.copy(bytes,result,length)     return result   else     return bytes   end if end function 

the error message isn't helpful. can't see wrong , i've tried can think of.

it turns out arrays need stored in reverse order:

function getbytes(bi biginteger,length int32) byte()   dim bytes() byte = bi.tobytearray   if bytes.length > length     dim result(length - 1) byte     array.copy(bytes,result,length)     array.reverse(result)     return result   else     array.reverse(bytes)     return bytes   end if end function 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -