Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Create string from Image blob & Another string.

$
0
0

Hello! I do have a complicated case. The task is get string (or maybe buffer) representation of the row data of an image from camera (it means i need binary data inside string). Than concat it with another string (ex. "token=1234&alfa=beta"). Then make it encrypted via HMAC SHA256 (that why I need only binary data, not base64).

Step by step:

  1. Problem part.
    var blob = event.media;
     
    console.log(blob.toString()); // makes [object Ti Blob]
    console.log(blob.getText()); // makes null
     
    // Can convert even in buffer:
     
    var blobStream = Ti.Stream.createStream({ source: blob, mode: Ti.Stream.MODE_READ });
    var buffer = Ti.createBuffer({ length: blob.length });
    var bytes = blobStream.read(buffer);
     
    console.log(buffer.toString()); // null
    console.log(Ti.Codec.decodeString({source:buffer, length:blob.length})); // null
  2. Success part.
    var str = "token=1234&alfa=beta";
  3. Success part.
    Titanium.include("../algorithm/hmac-sha256.js"); // CryptoJS by Google
    var res = CryptoJS.HmacSHA256(str + blobStringRepresentation, passphrase);

Appreciate any help!

1. The first approach. Does any one know how to get the binary data from image blob for forthcoming HMAC usage?

2. The second one. Does any one know the HMAC SHA256 representation for Titanium?


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>