Strings in MoonBit are UTF-16 LE encoded.
///|
test {
let input = "The quick brown fox jumps over the lazy dog"
inspect(
bytes_to_hex_string(sha1(@encoding.encode(UTF16, input))),
content="bd136cb58899c93173c33a90dde95ead0d0cf6df",
)
}///|
test {
let input = "The quick brown fox jumps over the lazy dog"
inspect(
bytes_to_hex_string(md5(@encoding.encode(UTF16, input))),
content="b0986ae6ee1eefee8a4a399090126837",
)
// buffered
let ctx = MD5::new()
ctx.update(b"a")
ctx.update(b"b")
ctx.update(b"c")
inspect(
bytes_to_hex_string(ctx.finalize()),
content="900150983cd24fb0d6963f7d28e17f72",
)
}///|
test {
let input = "The quick brown fox jumps over the lazy dog"
inspect(
bytes_to_hex_string(sm3(@encoding.encode(UTF16, input))),
content="fc2b31896629e88652ca1e3be449ec7ec93f7e5e29769f273fb973bc1858c66d",
)
//buffered
let ctx = SM3::new()
ctx.update(b"a".to_fixedarray())
ctx.update(b"b".to_fixedarray())
ctx.update(b"c".to_fixedarray())
inspect(
bytes_to_hex_string(ctx.finalize()),
content="66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0",
)
}trait ByteSourcepub(open) trait CryptoHasher {
fn size(Self) -> Int
fn block_size(Self) -> Int
fn reset(Self) -> Unit
fn update(Self, BytesView) -> Unit
fn finalize_into(Self, FixedArray[Byte], offset~ : Int) -> Unit
}type ChaChafn[K : ByteSource, N : ByteSource] ChaCha::chacha12(key : K, nonce : N, counter? : UInt) -> ChaCha raisefn[K : ByteSource, N : ByteSource] ChaCha::chacha20(key : K, nonce : N, counter? : UInt) -> ChaCha raisefn[K : ByteSource, N : ByteSource] ChaCha::chacha8(key : K, nonce : N, counter? : UInt) -> ChaCha raisefn[D : ByteSource] ChaCha::transform(self : ChaCha, data : D, target : FixedArray[Byte], offset? : Int) -> Unit#alias(MD5Context, deprecated="Use `MD5` instead")
type MD5#alias(Sha256Context, deprecated="Use `SHA256` instead")
type SHA256impl CryptoHasher for SHA256#alias(SM3Context, deprecated="Use `SM3` instead")
type SM3#deprecated("Use ChaCha::chacha12 and ChaCha::transform instead")
fn[Data : ByteSource] chacha12(key : FixedArray[UInt], counter : UInt, block : Data, nonce? : UInt) -> FixedArray[Byte] raise#deprecated("Use ChaCha::chacha20 and ChaCha::transform instead")
fn[Data : ByteSource] chacha20(key : FixedArray[UInt], counter : UInt, block : Data, nonce? : UInt) -> FixedArray[Byte] raise#deprecated("Use ChaCha::chacha8 and ChaCha::transform instead")
fn[Data : ByteSource] chacha8(key : FixedArray[UInt], counter : UInt, block : Data, nonce? : UInt) -> FixedArray[Byte] raiseexperimental packages for moonbitlang/core