CSharpTest.Net
BitSize Property
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > Salt Class : BitSize Property

Glossary Item Box

Returns the size of the salt in bits

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property BitSize As Salt.Size
C# 
public Salt.Size BitSize {get;}

Example

Library/Library.Test/TestSalt.cs

C#Copy Code
byte[] testValid = Encoding.ASCII.GetBytes("12345678");
Assert.AreEqual(Salt.Size.b64, Salt.FromBytes(testValid).BitSize);
Assert.AreEqual(testValid, Salt.FromBytes(testValid).ToArray());
testValid = null;

//now test with an odd number of bytes, should always hash to Sha256
byte[] notValid = Encoding.ASCII.GetBytes("0123456789");
Assert.AreNotEqual(Salt.Size.b64, Salt.FromBytes(notValid).BitSize);
Assert.AreNotEqual(testValid, Salt.FromBytes(notValid).ToArray());

Assert.AreEqual(Salt.Size.b256, Salt.FromBytes(notValid).BitSize);
Assert.AreEqual(Hash.SHA256(notValid).ToArray(), Salt.FromBytes(notValid).ToArray());
VB.NETCopy Code
Dim testValid As Byte() = Encoding.ASCII.GetBytes("12345678")
Assert.AreEqual(Salt.Size.b64, Salt.FromBytes(testValid).BitSize)
Assert.AreEqual(testValid, Salt.FromBytes(testValid).ToArray())
testValid = Nothing

'now test with an odd number of bytes, should always hash to Sha256
Dim notValid As Byte() = Encoding.ASCII.GetBytes("0123456789")
Assert.AreNotEqual(Salt.Size.b64, Salt.FromBytes(notValid).BitSize)
Assert.AreNotEqual(testValid, Salt.FromBytes(notValid).ToArray())

Assert.AreEqual(Salt.Size.b256, Salt.FromBytes(notValid).BitSize)
Assert.AreEqual(Hash.SHA256(notValid).ToArray(), Salt.FromBytes(notValid).ToArray())

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys