rust 除了ascii和decimal,这是什么数据格式?

zqry0prt  于 2022-12-19  发布在  其他
关注(0)|答案(1)|浏览(117)

请考虑以下几点:

use sha2::{Sha256,Digest};

fn main() {
    let mut hasher = Sha256::new();
    hasher.update(b"hello world");
    let result = hasher.finalize();

    let str_result = format!("{:x}", result);

    println!("A string is: {:x}", result);
    println!("ASCII decimal maps: {:?}", str_result.bytes());
    println!("What data coding is this?: {:?}", result);
}
The SHA256 hash as a string is: b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
ASCII decimal maps: Bytes(Copied { it: Iter([98, 57, 52, 100, 50, 55, 98, 57, 57, 51, 52, 100, 51, 101, 48, 56, 97, 53, 50, 101, 53, 50, 100, 55, 100, 97, 55, 100, 97, 98, 102, 97, 99, 52, 56, 52, 101, 102, 101, 51, 55, 97, 53, 51, 56, 48, 101, 101, 57, 48, 56, 56, 102, 55, 97, 99, 101, 50, 101, 102, 99, 100, 101, 57]) })
What data coding is this?:  [185, 77, 39, 185, 147, 77, 62, 8, 165, 46, 82, 215, 218, 125, 171, 250, 196, 132, 239, 227, 122, 83, 128, 238, 144, 136, 247, 172, 226, 239, 205, 233]

前两种是有意义的,我们有ASCII表示,然后是ASCII〉DecimalMap。第三种格式是什么?[185, 77, 39, 185, 147, 77, 62, 8, 165, 46, 82, 215, 218, 125, 171, 250, 196, 132, 239, 227, 122, 83, 128, 238, 144, 136, 247, 172, 226, 239, 205, 233]

ecbunoof

ecbunoof1#

它是表示为小数数组而不是十六进制字符串的哈希字节。
b94d27... -〉[185, 77, 39 ...]

  • 0xb9 -〉185
  • 0x4d -〉77
  • 0x27 -〉39

相关问题