简体   繁体   English

如何读取文件并转换为字节

[英]How to Read File and Convert to Byte

I am currently study on AES, There are several good site explaining and giving example about AES Encryption in java such as this . 我目前的AES研究,有几个很好的网站解释,并给予例如约AES加密在Java中,如 Example show AES encrypt String into byte. 示例显示AES将String加密为字节。

My question is how to convert application such as exe, txt and mp3? 我的问题是如何转换应用程序,例如exe,txt和mp3? I understand i have to convert the application into byte before encryption can be implement but how do you achieve that? 我知道我必须先将应用程序转换为字节,然后才能实施加密,但是您如何实现的呢?

The SO here and here explain about encrypt executable file but does not answer my question. 此处此处的SO说明了有关加密可执行文件的信息,但未回答我的问题。

FileInputStream将文件读入字节数组。

You may use NIO2 for random access files . 您可以将NIO2用于随机访问文件 This will represent the file data with a ByteBuffer . 这将使用ByteBuffer表示文件数据。 This is generally more efficient than using streams. 通常,这比使用流更有效。 The Java encryption classes happily accommodate you by supplying encryption methods on ByteBuffer - update and doFinal specifically. Java加密类通过在ByteBuffer上提供加密方法(特别是updatedoFinal愉快地适应您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM