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",
)
}///|
test {
inspect(
bytes_to_hex_string(md4(b"abc")),
content="a448017aaf21d8525fc10ae87aa6729d",
)
}///|
test {
inspect(
bytes_to_hex_string(ripemd160(b"abc")),
content="8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
)
}///|
test {
inspect(
bytes_to_hex_string(sha512(b"abc")),
content="ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
)
inspect(
bytes_to_hex_string(sha384(b"abc")),
content="cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7",
)
}///|
test {
let key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
let data = b"0123456789abcdef0123456789abcdef"
let encrypted = aes_ecb_encrypt(key, data)
inspect(
aes_ecb_decrypt(key, encrypted),
content="b\"0123456789abcdef0123456789abcdef\"",
)
}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
}pub suberror ChaChaError {
CounterExhausted
InvalidOutputRange
}pub suberror CryptoError {
InvalidCrypto(msg~ : String)
}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) -> Unitfn[D : ByteSource] ChaCha::transform_checked(self : ChaCha, data : D, target : FixedArray[Byte], offset? : Int) -> Unit raise ChaChaErrortype MD4impl CryptoHasher for MD4#alias(MD5Context, deprecated="Use `MD5` instead")
type MD5impl CryptoHasher for MD5type RIPEMD160impl CryptoHasher for RIPEMD160type SHA224impl CryptoHasher for SHA224#alias(Sha256Context, deprecated="Use `SHA256` instead")
type SHA256impl CryptoHasher for SHA256type SHA512impl CryptoHasher for SHA512#alias(SM3Context, deprecated="Use `SM3` instead")
type SM3impl CryptoHasher for 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] raiseInstall
Download zipexperimental packages for moonbitlang/core