C# 程序:将十六进制数据转换为普通文本:导入库错误
这是我的 C# 程序:我必须将十六进制数据解码为可读格式的普通文本。我更喜欢使用 apache 库中的 Hex 类,我从 http://commons.apache.org/ 下载codec/download_codec.cgi ,这是一个 jar 文件。
C# 编译器不接受 Jar 文件。因此,经过一番谷歌搜索后,我发现我必须首先使用 Visual Studio 中的 jbimp.exe 将 commons-codec jar 文件转换为 MSIL,然后导入它。我使用 Visual Studio 2010。但我找不到 jbimp.exe 实用程序来将此 jar 转换为 MSIL。我无法在我的系统上找到 JBimp 实用程序。
请帮助我如何以及在哪里可以获得 jbimp 实用程序?我还必须如何将 MSIL 代码指定为 C# 文件的包/命名空间?
我的 C# 代码:
using org.apache.commons.codec.binary.Hex;
class mainw
{
private static byte[] secret = new byte[]
{0x33, 0x34, 0x36, 0x32, 0x33, 0x36, 0x36, 0x36, 0x33, 0x36,
0x36, 0x32, 0x33, 0x36, 0x36, 0x36, 0x33, 0x37, 0x33, 0x33,
0x33, 0x36, 0x33, 0x32, 0x33, 0x37, 0x33, 0x35, 0x33, 0x36,
0x36, 0x33, 0x33, 0x36, 0x36, 0x33, 0x33, 0x36, 0x33, 0x35};
public static void main(string[] args)
{
Hex hex = new Hex();
byte[] secretDecoded1 = hex.decode(secret);
byte[] secretDecoded2 = hex.decode(secretDecoded1);
System.out.println("The secret is: "+new String(secretDecoded2));
}
}
This is my C# program: I have to decode Hex data into normal text in readable format. I prefer to use Hex class from apache library which i downloaded from http://commons.apache.org/codec/download_codec.cgi ,which is a jar file.
Jar files are not accepted by C# compilers. So after bit of googling, i came to know that i have to convert the commons-codec jar file into MSIL first using jbimp.exe from Visual Studio and then import it. I use Visual Studio 2010. But i couldnt find jbimp.exe utility to convert this jar to MSIL. I am unable to find JBimp utility on my system.
Please help me how and where can i get jbimp utility? and also how must i specify the MSIL code as package/namespace to C# file?
My C# code:
using org.apache.commons.codec.binary.Hex;
class mainw
{
private static byte[] secret = new byte[]
{0x33, 0x34, 0x36, 0x32, 0x33, 0x36, 0x36, 0x36, 0x33, 0x36,
0x36, 0x32, 0x33, 0x36, 0x36, 0x36, 0x33, 0x37, 0x33, 0x33,
0x33, 0x36, 0x33, 0x32, 0x33, 0x37, 0x33, 0x35, 0x33, 0x36,
0x36, 0x33, 0x33, 0x36, 0x36, 0x33, 0x33, 0x36, 0x33, 0x35};
public static void main(string[] args)
{
Hex hex = new Hex();
byte[] secretDecoded1 = hex.decode(secret);
byte[] secretDecoded2 = hex.decode(secretDecoded1);
System.out.println("The secret is: "+new String(secretDecoded2));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅仅为了十六进制操作而将 Java 库转换为 IL 完全是多余的。老实说,将 Java 库转换为 IL 很少是一个好主意 - 几乎总是有一个“本机”.NET 等效库可用,遵循 .NET 习惯用法等。
目前还不清楚您的开始意图是什么老实说,如果您从字节数组开始并希望将其转换为文本,那么您通常会使用类似
...的内容,使用适当的编码。
要将十六进制数据(自然是文本,而不是字节)解析为其二进制等效项(这是一个字节数组),您可以使用类似于我在 这个堆栈溢出答案。
It's complete overkill to convert a Java library to IL just for hex manipulation. It would very rarely be a good idea to convert a Java library to IL at all, to be honest - there's almost always a "native" .NET equivalent library available, following .NET idioms etc.
It's not really clear what you mean to start with, to be honest - if you're starting with a byte array and want to convert that into text, you'd normally use something like
... using whichever encoding is appropriate.
To parse hex data (which is naturally text, not bytes) into its binary equivalent (which is a byte array) you could use something like the code I posted in this Stack Overflow answer.
我不是 100% 确定我正确理解了这个问题,但这里是我用来将十六进制数据转换为 Microsoft CRM 附件的 C# 中可读文本的代码:
由于这是标准 C# 代码,您可以利用它来写入字符串变量一个文件的文件,如果这就是您想要做的。
皮特
I am not 100% sure I understand the question correctly, but here is the code I use to convert Hex data to readable text in C# for Microsoft CRM attachments:
Since this is standard C# code you could utilize it to write to a string variable instead of a file if that's what you are trying to do.
Pete