开发者

c++ parse file and read binary

I want to save email accounts and passwords, which I will have previously encrypted with an algorithm. T开发者_如何学编程hey need to be saved and read as binaries, with fwite and fread. What I want, is to be able to know if it's a pass or an email account, saving it between < e > < e > and < u > < u >

For example:

<e> !"§(!"$)Asdn12§(!"§UASD <e>
<u> !"§()!="§ksd!"§KM!"§lkm12 <u>
<e> !"§KMK!M"§asd9i1ikm23ß0 <e>
<u> l,1ö2l3!"§)IQASD=K!"E <u>

how do you suggest should I read the file as binary but be also able to parse it.

Those emails and passes are read by another prog which performs some tasks with them.


If usernames and passwords are always paired I suggest you store the length (in number of bytes) before each username and before each password. This way you can read the length (say a 4 byte integer) and know how long the next username / password record will be. You can then repeat this without worrying about searching for tags that could occur within a username or password.


You're doing it wrong. Writing your own crypto is a general no-no.

If you need to save usernames and passwords for authentication or logging into services, I recommend saving it normally but relying on the OS's file permissions to keep it safe (this is standard Unix practice, as if the OS is compromised you've lost anyway).

If you do need publicly-readable but encrypted passwords, use a freely-available encryption library and put the decryption key right into the source code (and compiled binary). This is as secure as you can be, since an attacker can just read the memory after decryption anyway.

I strongly recommend thinking about why you need encryption, and who you're trying to hide the information from.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜