如何将MD5哈希值转换为字符串,并把它作为一个文件名 [英] How to convert an MD5 hash to a string and use it as a file name

查看:420
本文介绍了如何将MD5哈希值转换为字符串,并把它作为一个文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以一个图像文件的MD5哈希值,我想使用哈希作为文件名。

I am taking the MD5 hash of an image file and I want to use the hash as a filename.

我如何散列转换为一个字符串,它是有效的文件名

How do I convert the hash to a string that is valid filename?

编辑:<?code>的toString()只是给System.Byte []

toString() just gives "System.Byte[]"

推荐答案

这个怎么样:

string filename = BitConverter.ToString(yourMD5ByteArray);

如果你喜欢不带连字符短文件名,那么你可以使用:

If you prefer a shorter filename without hyphens then you can just use:

string filename =
    BitConverter.ToString(yourMD5ByteArray).Replace("-", string.Empty);

这篇关于如何将MD5哈希值转换为字符串,并把它作为一个文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆