sha256() - > Bytes- 수신자
- Bytes
- 최소 인자 수
- 0
- 최대 인자 수
- 0
Declaration and parameters
링크사용 조건
기본 포함 · 미정
Import std.bytes in language mode 5.21.
The current compiler selects std/bytes.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
수신자
Bytes
매개변수 제약
Bytes.crc32 returns the unsigned CRC-32/ISO-HDLC value as an int from 0 through 4294967295.
CRC-32 uses width 32, polynomial 0x04c11db7, reflected input and output, initial value 0xffffffff, and final XOR 0xffffffff.
Bytes.sha256 and Bytes.sha512 implement FIPS 180-4 and return 32 and 64 digest bytes respectively.
Bytes.hmacSha256 uses its receiver as the key and its argument as the message. It returns the 32-byte HMAC-SHA-256 value from RFC 2104.
HMAC hashes a key longer than the 64-byte SHA-256 block before zero-padding it. Empty keys and messages are valid.
Empty input is valid for every checksum and digest. CRC-32 of empty input is zero.
These operations process stored bytes without decoding or normalization. Inputs remain unchanged and correctly typed calls have no data-dependent failure.
The receiver and any message argument evaluate once in that order. No external state, random input, or I/O affects the result.
Use toHex or toBase64 on a digest when a text encoding is required. Those encodings are separate from the digest bytes.
관련 규칙 · Compute interoperable checksums and digests →결과
The declared result type is Bytes.
효과
실패
Result and effects
링크Return the 32-byte SHA-256 digest of the exact receiver bytes.
Resolved contracts
링크Related entries
링크Compute interoperable checksums and digests
링크Compute interoperable checksums and digests
Bytes.crc32 returns the unsigned CRC-32/ISO-HDLC value as an int from 0 through 4294967295.
CRC-32 uses width 32, polynomial 0x04c11db7, reflected input and output, initial value 0xffffffff, and final XOR 0xffffffff.
Bytes.sha256 and Bytes.sha512 implement FIPS 180-4 and return 32 and 64 digest bytes respectively.
Bytes.hmacSha256 uses its receiver as the key and its argument as the message. It returns the 32-byte HMAC-SHA-256 value from RFC 2104.
HMAC hashes a key longer than the 64-byte SHA-256 block before zero-padding it. Empty keys and messages are valid.
Empty input is valid for every checksum and digest. CRC-32 of empty input is zero.
These operations process stored bytes without decoding or normalization. Inputs remain unchanged and correctly typed calls have no data-dependent failure.
The receiver and any message argument evaluate once in that order. No external state, random input, or I/O affects the result.
Use toHex or toBase64 on a digest when a text encoding is required. Those encodings are separate from the digest bytes.
이유
Named standard algorithms must agree with independent implementations. Keeping digest bytes separate from their text representation makes the same digest usable in binary and text formats.
Match established checksum and hash vectors
링크import std.bytes { Bytes }import std.ioio.writeLine("{Bytes.empty().crc32()}")let checksum = "123456789".encodeUtf8().crc32()io.writeLine("{checksum}")io.writeLine("abc".encodeUtf8().sha256().toHex())io.writeLine("abc".encodeUtf8().sha512().toHex())io.writeLine("key".encodeUtf8().hmacSha256("The quick brown fox jumps over the lazy dog".encodeUtf8()).toHex())
0
3421780262
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
03421780262ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015adddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49ff7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8