Log in or register to post comments


December 27, 2012 - 7:06am #1


I have not been able to find a sample from SignatureBuilder
SignatureBuilder Where can I find them?



February 18, 2013 - 11:22pm #13


I have followed all instructions to execute the program, it running, but when I connect with my own cloud database then its not recognize image from my own cloud database, it shows authentication error, In my Country the time zone is GMT+5.30. I mention here SignatureBuilder.java code


package com.qualcomm.vuforia.VisualSearch.utils;
import android.annotation.SuppressLint;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.SignatureException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
public class SignatureBuilder {
public String tmsSignature(HttpUriRequest request, String secretKey) {
String method = request.getMethod();
String contentType = "";
String hexDigest = "d41d8cd98f00b204e9800998ecf8427e"; // Hex digest of an empty string
if (method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("DELETE")) {
// Do nothing because the strings are already set correctly
} else if (method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("PUT")) {
contentType = "application/json";
// If this is a POST or PUT the request should have a request body
hexDigest = contentMD5((HttpEntityEnclosingRequestBase) request);
} else {
System.out.println("ERROR: Invalid content type passed to Sig Builder");
// Date in the header and date used to calculate the hash must be the same
String dateValue = request.getFirstHeader("Date").getValue();
String requestPath = request.getURI().getPath();
String toDigest = new String(method + "\n" + hexDigest + "\n" + contentType + "\n" + dateValue + "\n" + requestPath);
String shaHashed = "";
try {
shaHashed = calculateRFC2104HMAC(secretKey, toDigest);
} catch (SignatureException e) {
return new String(shaHashed);
private String contentMD5(HttpEntityEnclosingRequestBase httpMethod) {
ByteArrayOutputStream requestOutputStream = new ByteArrayOutputStream();
try {
catch (IOException e)
System.out.println("ERROR: IOException caught when writing Content MD5 hash");
        return DigestUtils.md5Hex(requestOutputStream.toByteArray()).toLowerCase();
public static String calculateRFC2104HMAC(String key, String data) throws java.security.SignatureException {
String result = "";
try {
// get an hmac_sha1 key from the raw key bytes
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), "HmacSHA1");
// get an hmac_sha1 Mac instance and initialize with the signing key
Mac mac = Mac.getInstance("HmacSHA1");
// compute the hmac on input data bytes
byte[] rawHmac = mac.doFinal(data.getBytes());
// base64-encode the hmac
result = new String(Base64.encodeBase64(rawHmac, false));
} catch (Exception e) {
return result;

Best practices for user

January 11, 2013 - 11:40am #12

Best practices for user submitted images is to relay these submissions through a gateway to VWS so that you can manage the connection behavior and API interactions w/ the database(s) that your app is using. This approach also provides you a lot more security and flexibility in administering your Cloud Databases because you're not distributing your server keys with your app. 

and actually, NalinS... 

January 11, 2013 - 11:39am #11

and actually, NalinS...  Since I'm probably going to have to do this myself...  in StringBuilder.java, what is presumed to be inside httpMethod.getEntity which gets written to an output stream? is it just "POST"?

private String contentMD5(HttpEntityEnclosingRequestBase httpMethod) {
        ByteArrayOutputStream requestOutputStream = new ByteArrayOutputStream();
        try {
        } catch (IOException e) {
            System.out.println("ERROR: IOException caught when writing Content MD5 hash");
        return DigestUtils.md5Hex(requestOutputStream.toByteArray()).toLowerCase();

I don't mind however long it

January 11, 2013 - 11:14am #10

I don't mind however long it takes the VWS Cloud Hamsters to spin the wheels to get the image in my cloud database. I can periodically poll for a response in a Coroutine or something pseudo-clever.

I can't be the first person to think of this. Has anyone ported SignatureBuilder.java to C#?  If anyone has, and you send it to me before I tear all of my hair out I'll buy you a beer.

The VWS API typical use case

January 11, 2013 - 10:48am #9

The VWS API typical use case is for the mass uploading of Images, hence the java examples highlight how to do this.

Although there is nothing to prevent the use case you are talking about (device upload to databases) you will have to write your own code to do this upload and additionally you may run into certain latency issues i.e. it can take some time for images to be made available for recognition in the Cloud.


I am aiming to take a picture

January 11, 2013 - 10:32am #8

I am aiming to take a picture using the camera's phone and to upload that image as a cloud target via the VWS API.... I'm using Unity.  Am I expected to recreate everything related in StringBuilder, etc.? Or is there some Unity utility script that I just haven't found yet?

The current version has

January 8, 2013 - 6:04am #7

The current version has SignatureBuilder - VWS Sample Code

i don't have this java file too

January 8, 2013 - 5:37am #6

I have same problem, please send one to me,thanks so much!



December 27, 2012 - 8:01am #5

I got it. 

Thank you so much!



I just checked, and you're

December 27, 2012 - 7:52am #4

I just checked, and you're right - thanks for catching that. See your email.

  In VWS Sample, I could not

December 27, 2012 - 7:48am #3


In VWS Sample, I could not find "SignatureBuilder.java".
All the file in the link you gave below.










If you have an "SignatureBuilder.java",
Receive mail?

It is part of the VWS sample

December 27, 2012 - 7:36am #2

It is part of the VWS sample code - VWS Sample Code

Log in or register to post comments