e-CryptIt Engine Xojo Plugin |
|
SHA_256 Class (console safe)
SHA_256 is a message digest/hash algorithm with a digest/hash size of 256 bits (32 characters).
This algorithm has been tested against official test vectors.
Object
SHA_256
class SHA_256 implements
IHashAlgorithm
Methods
Final | Use this function when you are done adding bytes to the SHA_256 class. |
Update | Use this method to add data with MemoryBlock to the SHA_256 stream. |
Update | Use this method to add data with String to the SHA_256 stream. |
Test case for a known test vector
Dim data as String
Dim hash as SHA_256
Dim result as String
Dim hexResult as String
Dim i as Integer
data = "abc"
// We do this in ASCII because the well known test vectors come in ASCII
data = ConvertEncoding(data,Encodings.ASCII)
hash = new SHA_256()
hash.Update(data)
result = hash.Final()
// Convert to HEX
For i = 1 to 32
hexResult = hexResult + Right("0"+Hex(Asc(Mid(result,i,1))),2)
next
if hexResult <> "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" then
return false
end if
// Lets test another official vector
data = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
// We do this in ASCII because the well known test vectors come in ASCII
data = ConvertEncoding(data,Encodings.ASCII)
hash = new SHA_256()
hash.Update(data)
result = hash.Final()
hexResult = ""
// Convert to HEX
For i = 1 to 32
hexResult = hexResult + Right("0"+Hex(Asc(Mid(result,i,1))),2)
next
if hexResult = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" then
return true
else
return false
end if
Supported Platforms:
MacOS X Cocoa 32 bitMacOS X Cocoa 64 bitWindows 32 bitWindows 64 bitLinux 32 bitLinux 64 bitLinux ARM