J
John
Hi,
In a nutshell, why am I getting the results I am getting? I would have
expected a call to method1( n) to return an 'n' length string.
At first I thought it was a problem in my function, but after finding an
article showing how to do the salt, I noticed, they had basically the same
code as me. So obviously, I'm so lost, I didn't even know I was lost.
Can somebody please direct me to an online article explaining what I don't
understand.
Thanks
-- class --
class Class1
{
static void Main(string[] args)
{
for( int len = 10; len <30; len++)
{
string s = Class1.Method1( len);
Console.Out.WriteLine( "Method1({0}) results : {1} and len={2}", len,
s, s.Length);
}
Console.Out.WriteLine( "press enter to exit");
Console.In.Read();
}
// from internet
public static string Method1( int saltLen)
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] buff = new byte[saltLen];
rng.GetBytes(buff);
return Convert.ToBase64String(buff);
}
}
-- output --
Method1(10) results : vQERIYXmGC7K/w== and len=16
Method1(11) results : RaA9HXz31CjigAg= and len=16
Method1(12) results : g3CbTZskaCCUjFDU and len=16
Method1(13) results : GInzz5LJpUXkOnaJ4Q== and len=20
Method1(14) results : UyTlZoOACCSTswc6IBI= and len=20
Method1(15) results : 8bJ3AvmJRqZy2Sw3wy+8 and len=20
Method1(16) results : 9PeRWzfrhGjzl27WOa1iyw== and len=24
Method1(17) results : bUHbbeLpLFQrn/RDzf01Ny0= and len=24
Method1(18) results : 3ZBiY++Vcd8reojolOmfPpfg and len=24
Method1(19) results : 3ToL3JDa9naqJrHlQQm/kUg8Vg== and len=28
Method1(20) results : OINljarFIM2uAypPLzMl6qfLN60= and len=28
Method1(21) results : R3PGSjLnhTrAxRrUVFXpL1DCrkNH and len=28
Method1(22) results : L/XiRyRWkU9+GrQnGkB5hzvtgA5LPQ== and len=32
Method1(23) results : YSwyvS2X5C7I0zxdNL8nSa7h/6T1fAM= and len=32
Method1(24) results : kHkaClhr+XutyhFUX0j3I/Hu9iko0Cvm and len=32
Method1(25) results : a5wFU26nON85AjkVQ+2A+1g+NqTq4UCuzw== and len=36
Method1(26) results : 1gPsznq6t4x1ME0ohfiZ2FtV0qBUWfbOtzE= and len=36
Method1(27) results : 03gkSPvg9oLS7u8Ic3XsGVZ90+R9WmF0uuKz and len=36
Method1(28) results : SMS+B8+xBz2xapyrg572Awrf0W9jydbExXTs+g== and len=40
Method1(29) results : m+LkKfPVOaJi7J2giJpDqFGEJoxu4WgLBK/qyC4= and len=40
press enter to exit
In a nutshell, why am I getting the results I am getting? I would have
expected a call to method1( n) to return an 'n' length string.
At first I thought it was a problem in my function, but after finding an
article showing how to do the salt, I noticed, they had basically the same
code as me. So obviously, I'm so lost, I didn't even know I was lost.
Can somebody please direct me to an online article explaining what I don't
understand.
Thanks
-- class --
class Class1
{
static void Main(string[] args)
{
for( int len = 10; len <30; len++)
{
string s = Class1.Method1( len);
Console.Out.WriteLine( "Method1({0}) results : {1} and len={2}", len,
s, s.Length);
}
Console.Out.WriteLine( "press enter to exit");
Console.In.Read();
}
// from internet
public static string Method1( int saltLen)
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] buff = new byte[saltLen];
rng.GetBytes(buff);
return Convert.ToBase64String(buff);
}
}
-- output --
Method1(10) results : vQERIYXmGC7K/w== and len=16
Method1(11) results : RaA9HXz31CjigAg= and len=16
Method1(12) results : g3CbTZskaCCUjFDU and len=16
Method1(13) results : GInzz5LJpUXkOnaJ4Q== and len=20
Method1(14) results : UyTlZoOACCSTswc6IBI= and len=20
Method1(15) results : 8bJ3AvmJRqZy2Sw3wy+8 and len=20
Method1(16) results : 9PeRWzfrhGjzl27WOa1iyw== and len=24
Method1(17) results : bUHbbeLpLFQrn/RDzf01Ny0= and len=24
Method1(18) results : 3ZBiY++Vcd8reojolOmfPpfg and len=24
Method1(19) results : 3ToL3JDa9naqJrHlQQm/kUg8Vg== and len=28
Method1(20) results : OINljarFIM2uAypPLzMl6qfLN60= and len=28
Method1(21) results : R3PGSjLnhTrAxRrUVFXpL1DCrkNH and len=28
Method1(22) results : L/XiRyRWkU9+GrQnGkB5hzvtgA5LPQ== and len=32
Method1(23) results : YSwyvS2X5C7I0zxdNL8nSa7h/6T1fAM= and len=32
Method1(24) results : kHkaClhr+XutyhFUX0j3I/Hu9iko0Cvm and len=32
Method1(25) results : a5wFU26nON85AjkVQ+2A+1g+NqTq4UCuzw== and len=36
Method1(26) results : 1gPsznq6t4x1ME0ohfiZ2FtV0qBUWfbOtzE= and len=36
Method1(27) results : 03gkSPvg9oLS7u8Ic3XsGVZ90+R9WmF0uuKz and len=36
Method1(28) results : SMS+B8+xBz2xapyrg572Awrf0W9jydbExXTs+g== and len=40
Method1(29) results : m+LkKfPVOaJi7J2giJpDqFGEJoxu4WgLBK/qyC4= and len=40
press enter to exit