0

A webapp I created supports offline storage... but it very quickly becomes maxed out when users add 10-13 photos. The photos are stored as super long base64 encoded strings.... but can they be stored as sha1?

default_noob_network
  • 1,204
  • 3
  • 19
  • 39

1 Answers1

2

Hashing is different of Encryption/Encoding

Base64 is an Encoding Method witch means that you can Decode without the need of a key

SHA1 is an Hashing Method witch means that it will generate a string depending of the content to be hashed, it can not be decoded or decrypted

Then you have Encryption (for example AES) that you Encrypt the content with that algorithm and with a key, to decrypt the data you need the encryption method and the key, without one of these elements you can not decrypt the data.

If you store the photos as SHA1 it will save a lot of space, but you can never retrieve them because all you have is a string with the hashed content.

I don't think there is a way to escape the space occupied by the photos, you might try saving to a byte array but I think the occupied space is the same because you need all the photo information to be available again

Examples (Encoding, Hashing, Encrypting word "teste")

Base64 Encoding: dGVzdGU=
Website to test the encoding: https://www.base64encode.org/

SHA1 Hashing: 2e6f9b0d5885b6010f9167787445617f553a735f
Website to test the hashing to SHA1: http://www.sha1hash.com/

AES Encryption generates a byte array.
Base64 equivalent to the AES Byte Array: SUpXhKOAO1pQdXD2igf0cw==
Key used: key_to_encrypt_decrypt
Size: 128 Bit
Website to test the encryption of AES: http://aesencryption.net/

Pedro Cavaleiro
  • 835
  • 7
  • 21
  • Thanks for this answer... but what about git? Doesn't git turn everything you do into SHA1 basically? How does it retrieve the files in a commit? I am fairly new to git though so I might just be misunderstanding things. – default_noob_network Sep 23 '15 at 15:12
  • 1
    I don't think Git turns everything into SHA1 Hashes, just some security parts like passwords... I've never used Git so I can not be sure. I know what I've wrote above is correct. And Git must use an Encryption Method to save the files securely and the password to decrypt them is hashed IDK if using SHA1. I assume that is something like this. But again I'm not certain – Pedro Cavaleiro Sep 23 '15 at 15:24
  • 1
    What I gave you on the answer was a short description of how these 3 methods work. If you wish to learn more you can go to this website https://danielmiessler.com/study/encoding_encryption_hashing/ or search on Google and search for Encoding and Encryption – Pedro Cavaleiro Sep 23 '15 at 15:28
  • Git uses the hash of the content to identify it, different commits are linked together by referencing these hashes. Actual contents (source code, passwords, secret keys, ...) are stored compressed but unencrypted (so you wouldn't want to push those to GitHub!). Hashes are also used to confirm integrity of the repository, any data corruption would be detected as hashes don't match anymore. BitTorrent uses similar techniques (a Merkle tree), hashes are just metadata about original contents. – NikoNyrh Oct 06 '15 at 14:58