如何从二进制文件中读取十六进制值并存储在十六进制数组中. [英] How read hex values from binary file and storing in a hex array.

查看:123
本文介绍了如何从二进制文件中读取十六进制值并存储在十六进制数组中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要读取binari文件的最后32个字节,并将它们用作十六进制数组(这是解密的密钥).
如果我使用诸如
的硬编码密钥

Hi, i need to read last 32 byte of a binari file and use them as array of hex (it''s a key for decryption).
if i use an hardcoded key like


unsigned char aesKey[32] = {
    0x53, 0x28, 0x40, 0x6e, 0x2f, 0x64, 0x63, 0x5d, 0x2d, 0x61, 0x77, 0x40, 0x76, 0x71, 0x77, 0x28,
    0x74, 0x61, 0x7d, 0x66, 0x61, 0x73, 0x3b, 0x5d, 0x66, 0x6d, 0x3c, 0x3f, 0x7b, 0x66, 0x72, 0x36
};



它可以工作,但是如果我尝试根据从文件读取的十六进制值创建aesKey数组,则会崩溃.

有什么想法吗?

从下面的非解决方案复制的其他信息
这就是我从文件中读取最后32个字节的方式:



it works, but if i try to create the aesKey array from hex values readed from file, it crash.

any ideas?

additional information copied from non-solution below
this is how i read the last 32 byte from my file:

char *chiavegiusta;
inFile.open(filename, ios::binary);
inFile.seekg(-32, ios::end);
inFile.read((char *)chiavegiusta, 32);
inFile.close();



我的问题是如何从这些值创建一个十六进制数组.



my problem is how to create an hex array from these values.

推荐答案

报价:

有什么想法吗?

,可能您的程序无法正确读取文件中的数字.但是,您应该发布实际代码,以获得更好的帮助.

[更新]
您从未为数据分配内存.从
更改

Yes, probably your program doesn''t read correctly the numbers form the file. However, you should post the actual code, in order to get better help.

[update]
You never allocated memory for the data. change from

char *chiavegiusta;




to

unsigned char chiavegiusta[32];


[/update]


这就是我从文件中读取最后32个字节的方式:

this is how i read the last 32 byte from my file:

char *chiavegiusta;
    inFile.open(filename, ios::binary);
    inFile.seekg(-32, ios::end);
    inFile.read((char *)chiavegiusta, 32);
    inFile.close();



我的问题是如何从这些值创建一个十六进制数组.



my problem is how to create an hex array from these values.


这篇关于如何从二进制文件中读取十六进制值并存储在十六进制数组中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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