Blitz3D+ Command Reference

Sha256TextBytes ( value$ )

Parameters

value$ - the text to hash; its exact stored bytes are consumed

Description

Hashes a String's exact bytes and returns the raw SHA-256 digest as a 32-byte Bank.

The raw-bytes twin of Sha256Text: identical hashing, different packaging. Where the hex form suits logs and JSON, the 32 raw bytes suit binary formats - embed the digest straight into a binary save header with PokeByte/BankCopy-style code, write it with WriteBankAtomic, or compare digests byte-by-byte. Rendering the bytes as lowercase hex reproduces Sha256Text's output exactly.

Exactly the stored bytes are hashed - no BOM, terminator, newline conversion or normalization - and an empty string yields the standard empty-message digest. The returned Bank is always exactly 32 bytes.

The Bank is new and owned by you: free it with FreeBank like any Bank you created, and mind leaks when hashing in a loop.

SHA-256 is an integrity and identity primitive: not a password-storage API, and a bare hash does not authenticate data by itself. Siblings cover Banks (Sha256BankBytes) and files (Sha256FileBytes) - all worker-safe.

For the full rules, see the Application Data language reference.

Requires Extended mode.

See also: Sha256Text, Sha256BankBytes, Sha256FileBytes, FreeBank.

Example

; Sha256TextBytes Example
; -----------------------
; Requires Extended mode.

; Hash a save-game summary string as RAW bytes - useful when the
; digest is stored in a binary save header rather than as text
save_text$="player=Aria;gold=1250"
Print "Hashing: "+save_text
Print ""

; Sha256TextBytes returns a new owned 32-byte Bank
digest=Sha256TextBytes(save_text)
Print "Digest Bank size: "+BankSize(digest)+" bytes"

; Show the raw bytes as hex - it matches Sha256Text's hex output
hex_text$=""
For i=0 To BankSize(digest)-1
    hex_text=hex_text+Right(Hex(PeekByte(digest,i)),2)
Next
Print "Digest bytes:     "+Lower(hex_text)
Print "Sha256Text gives: "+Sha256Text(save_text)

; The digest Bank is owned by us and must be freed
FreeBank digest

Print ""
Print "Press any key to close the example"
WaitKey

End

Index