jsbeckr
jsbeckr

Reputation: 1193

Send and verify images via WebRTC

I need to send image data over WebRTC to another peer. My first thought was to use the base64 representation from the image. I get this data URI with the help of a Canvas. Works like a charm. But now I want to check if the data was not altered before sending.

The problem is, that the Canvas re-encodes the image and what's worth Firefox and Chrome encode the imageData differently. So I can't get matching SHA hashes.

Any ideas on how to solve this issue. Maybe a new approach to the whole problem? (WebRTC is mandatory though). Thanks!

Upvotes: 1

Views: 534

Answers (1)

jsbeckr
jsbeckr

Reputation: 1193

Here is what I did... Basically I'm working with ArrayBuffers and Blobs now. I have a Blob of the image in question. Then I use FileReader.readAsArrayBuffer(blob) and and UInt8Array as a view on that data. Then I concatinate the bytes and compute a MD5 hash with https://github.com/satazor/SparkMD5. Concatination takes quite a while, so I only take every tenth byte in consideration. Which is supposedly quite a big security issue. So any tips on improving this process are very appreciated. As long as I or someone else comes up with a better idea, I will keep this the answer.

Upvotes: 0

Related Questions