SignatureHelper Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.device.auth.SignatureHelper

public final class SignatureHelper

Builds the authorization signature as a composition of functions.

Constructor Summary

Modifier Constructor Description
protected SignatureHelper()

Method Summary

Modifier and Type Method and Description
static byte[] buildRawSignature(String resourceUri, long expiryTime)

Builds the raw signature.

static byte[] decodeDeviceKeyBase64(String deviceKey)

Decodes the deviceKey using Base64.

static byte[] encodeSignatureBase64(byte[] sig)

Encodes the signature using Base64 and then further encodes the resulting string using UTF-8 encoding.

static java.lang.String encodeSignatureUtf8(byte[] sig)

Encodes the signature using charset UTF-8.

static java.lang.String encodeSignatureWebSafe(String sig)

Safely escapes characters in the signature so that they can be transmitted over the internet.

static byte[] encryptSignatureHmacSha256(byte[] sig, byte[] deviceKey)

Encrypts the signature using HMAC-SHA256.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

SignatureHelper

protected SignatureHelper()

Method Details

buildRawSignature

public static byte[] buildRawSignature(String resourceUri, long expiryTime)

Builds the raw signature.

Parameters:

resourceUri - the resource URI.
expiryTime - the signature expiry time, as a UNIX timestamp.

Returns:

the raw signature.

decodeDeviceKeyBase64

public static byte[] decodeDeviceKeyBase64(String deviceKey)

Decodes the deviceKey using Base64.

Parameters:

deviceKey - the device key.

Returns:

the Base64-decoded device key.

encodeSignatureBase64

public static byte[] encodeSignatureBase64(byte[] sig)

Encodes the signature using Base64 and then further encodes the resulting string using UTF-8 encoding.

Parameters:

sig - the HMAC-SHA256 encrypted signature.

Returns:

the Base64-encoded signature.

encodeSignatureUtf8

public static String encodeSignatureUtf8(byte[] sig)

Encodes the signature using charset UTF-8.

Parameters:

sig - the HMAC-SHA256 encrypted, Base64-encoded signature.

Returns:

the signature encoded using charset UTF-8.

encodeSignatureWebSafe

public static String encodeSignatureWebSafe(String sig)

Safely escapes characters in the signature so that they can be transmitted over the internet. Replaces unsafe characters with a '%' followed by two hexadecimal digits (i.e. %2d).

Parameters:

sig - the HMAC-SHA256 encrypted, Base64-encoded, UTF-8 encoded signature.

Returns:

the web-safe encoding of the signature.

encryptSignatureHmacSha256

public static byte[] encryptSignatureHmacSha256(byte[] sig, byte[] deviceKey)

Encrypts the signature using HMAC-SHA256.

Parameters:

sig - the unencrypted signature.
deviceKey - the Base64-decoded device key.

Returns:

the HMAC-SHA256 encrypted signature.

Applies to