简体   繁体   English

将Byte数组和字符串存储在同一文件中

[英]Storing Byte arrays and strings in the same file

I am making a program which requires me to store login information for users. 我正在制作一个程序,该程序需要我为用户存储登录信息。 I already have the code set up which creates a hashed Byte[] array of their passwords and salts them with another Byte[] . 我已经设置了代码,该代码创建了他们的密码的哈希Byte[]数组,并用另一个Byte[]对其进行了盐化。 I would like to store their username, their password, and their salt in the same file, preferably something like username,password,hash . 我想将他们的用户名,密码和盐存储在同一文件中,最好是像username,password,hash类的东西。

All I have found so far are examples of storing only a Byte array. 到目前为止,我所发现的只是仅存储Byte数组的示例。 If anyone could point me in the right direction for writing and reading files like that, it would be great. 如果有人能指出正确的方向来编写和读取这样的文件,那就太好了。

Thank you for any help you can give me. 谢谢您能给我的任何帮助。

The simplest option would probably be to just convert the byte arrays to text using base64 or hex ( not calling new String(bytes) ) and then just use a property file or any other text storage scheme you fancy. 最简单的选择可能是仅使用base64或hex将字节数组转换为文本( 调用new String(bytes) ),然后仅使用属性文件或您喜欢的任何其他文本存储方案。

You could go the other way, and store everything in a binary format (eg using a length-prefixed message for both bytes and strings) but my experience is that the readability of text files is huge boon to development. 可以采用另一种方法,将所有内容都以二进制格式存储(例如,对字节和字符串都使用长度前缀的消息),但是我的经验是文本文件的可读性极大地促进了开发。

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

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