如何将HEX字符串转换为普通文本字符串C# [英] How to convert HEX string to normal text string C#

查看:389
本文介绍了如何将HEX字符串转换为普通文本字符串C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个keyMaterial HEX字符串。它看起来像这样




453F1287225ED9971D389A35F8D1032E7748DD0B88302F7C6C194626D4C8659B000000000E800000000200002000000047C2CA7B9A1F1C343CA228CC314A42F063A240E17624F886AF6CE9A135CAF65310000000D30489E536548F129E43240A26344811400000009EE2F5549B1447548ADADDD60A212C22DC2F9B2DC67D8E567B48B3847A525244A2F575AAFFB3AECD0385612BE7C38CA403BE6B5DFA8BEDEFBFA35C5ECC1818AB




您可以看到整个文件。我们如何将这个HEX代码转换为使用C#的普通文本字符串?我在C ++上有一些例子,它没有帮助我。你可以给一个建议吗?



这个字符串的编码是16291388(但它不是解决问题的方法)

解决方案

如果您查看OP的原始文件,他正尝试解码无线配置文件的keyMaterial。



这个数据不仅仅是用十六进制编码的,它也是加密的,这就是为什么把它转换成字符串会导致无意义的数据。

 < WLANProfile xmlns =http://www.microsoft.com/networking/WLAN/profile/v1> 
<名称> TP-LINK_D84690< /名称>
< SSIDConfig>
< SSID>
< hex> 54502D4C494E4B5F443834363930< / hex>
<名称> TP-LINK_D84690< /名称>
< / SSID>
< / SSIDConfig>
< connectionType> ESS< / connectionType>
< connectionMode> auto< / connectionMode>
< MSM>
< security>
< auth加密>
< authentication> WPA2PSK< / authentication>
< encryption> AES< / encryption>
< useOneX> false< / useOneX>
< / authEncryption>
< sharedKey>
< keyType> passPhrase< / keyType>
< protected> true< / protected>
将keyMaterial> 01000000D08C9DDF0115D1118C7A00C04FC297EB01000000E72F4D29E2AD8E40BBAD5B02842DA10000000000020000000000106600000001000020000000453F1287225ED9971D389A35F8D1032E7748DD0B88302F7C6C194626D4C8659B000000000E800000000200002000000047C2CA7B9A1F1C343CA228CC314A42F063A240E17624F886AF6CE9A135CAF65310000000D30489E536548F129E43240A26344811400000009EE2F5549B1447548ADADDD60A212C22DC2F9B2DC67D8E567B48B3847A525244A2F575AAFFB3AECD0385612BE7C38CA403BE6B5DFA8BEDEFBFA35C5ECC1818AB< / keyMaterial>
< / sharedKey>
< / security>
< / MSM>
< / WLANProfile>

这些数据是经过加密的,因此您不能将其解码为字符串。

We have a keyMaterial HEX string. It looks like this

453F1287225ED9971D389A35F8D1032E7748DD0B88302F7C6C194626D4C8659B000000000E800000000200002000000047C2CA7B9A1F1C343CA228CC314A42F063A240E17624F886AF6CE9A135CAF65310000000D30489E536548F129E43240A26344811400000009EE2F5549B1447548ADADDD60A212C22DC2F9B2DC67D8E567B48B3847A525244A2F575AAFFB3AECD0385612BE7C38CA403BE6B5DFA8BEDEFBFA35C5ECC1818AB

You can see the whole file. How can we translate this HEX code to normal text string with C#? I have some examples on C++, it hasn't helped me. Can you give an advise?

THE ENCODING OF THIS STRING IS 16291388 (but it's not a solution of the problem)

解决方案

If you look at the OP's original file he is trying to decode the keyMaterial of a wireless profile.

This data is not just encoded in hex, it is also encrypted which is why just converting it to a string results in nonsensical data.

<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
    <name>TP-LINK_D84690</name>
    <SSIDConfig>
        <SSID>
            <hex>54502D4C494E4B5F443834363930</hex>
            <name>TP-LINK_D84690</name>
        </SSID>
    </SSIDConfig>
    <connectionType>ESS</connectionType>
    <connectionMode>auto</connectionMode>
    <MSM>
        <security>
            <authEncryption>
                <authentication>WPA2PSK</authentication>
                <encryption>AES</encryption>
                <useOneX>false</useOneX>
            </authEncryption>
            <sharedKey>
                <keyType>passPhrase</keyType>
                <protected>true</protected>
                <keyMaterial>01000000D08C9DDF0115D1118C7A00C04FC297EB01000000E72F4D29E2AD8E40BBAD5B02842DA10000000000020000000000106600000001000020000000453F1287225ED9971D389A35F8D1032E7748DD0B88302F7C6C194626D4C8659B000000000E800000000200002000000047C2CA7B9A1F1C343CA228CC314A42F063A240E17624F886AF6CE9A135CAF65310000000D30489E536548F129E43240A26344811400000009EE2F5549B1447548ADADDD60A212C22DC2F9B2DC67D8E567B48B3847A525244A2F575AAFFB3AECD0385612BE7C38CA403BE6B5DFA8BEDEFBFA35C5ECC1818AB</keyMaterial>
            </sharedKey>
        </security>
    </MSM>
</WLANProfile>

This data is encrypted so you cannot just decode it into a string.

这篇关于如何将HEX字符串转换为普通文本字符串C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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