microsoft-azure-storage/src/com/microsoft/azure/storage/core/SharedAccessSignatureHelper.java
public static UriQueryBuilder generateSharedAccessSignatureForAccount(
            final SharedAccessAccountPolicy policy, final String signature)
            throws StorageException {
        
        Utility.assertNotNull("policy", policy);
        
        Utility.assertNotNull("signature", signature);

        String permissions = null;
        Date startTime = null;
        Date expiryTime = null;
        IPRange ipRange = null;
        SharedAccessProtocols protocols = null;
        String services = null;
        String resourceTypes = null;
        if (policy != null) {
            permissions = policy.permissionsToString();
            startTime = policy.getSharedAccessStartTime();
            expiryTime = policy.getSharedAccessExpiryTime();
            ipRange = policy.getRange();
            protocols = policy.getProtocols();
            services = policy.servicesToString();
            resourceTypes = policy.resourceTypesToString();
        }

        final UriQueryBuilder builder = new UriQueryBuilder();

        builder.add(Constants.QueryConstants.SIGNED_VERSION, Constants.HeaderConstants.TARGET_STORAGE_VERSION);
        
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_SERVICE, services);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_RESOURCE_TYPE, resourceTypes);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_PERMISSIONS, permissions);

        final String startString = Utility.getUTCTimeOrEmpty(startTime);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_START, startString);

        final String stopString = Utility.getUTCTimeOrEmpty(expiryTime);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_EXPIRY, stopString);

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_RESOURCE, resourceTypes);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_IP, ipRange != null ? ipRange.toString() : null);
        addIfNotNullOrEmpty(
                builder, Constants.QueryConstants.SIGNED_PROTOCOLS, protocols != null ? protocols.toString() : null);

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNATURE, signature);

        return builder;
    }
public static UriQueryBuilder generateSharedAccessSignatureForAccount(
            final SharedAccessAccountPolicy policy, final String signature)
            throws StorageException {
        
        Utility.assertNotNull("policy", policy);
        
        Utility.assertNotNull("signature", signature);

        String permissions = null;
        Date startTime = null;
        Date expiryTime = null;
        IPRange ipRange = null;
        SharedAccessProtocols protocols = null;
        String services = null;
        String resourceTypes = null;
        if (policy != null) {
            permissions = policy.permissionsToString();
            startTime = policy.getSharedAccessStartTime();
            expiryTime = policy.getSharedAccessExpiryTime();
            ipRange = policy.getRange();
            protocols = policy.getProtocols();
            services = policy.servicesToString();
            resourceTypes = policy.resourceTypesToString();
        }

        final UriQueryBuilder builder = new UriQueryBuilder();

        builder.add(Constants.QueryConstants.SIGNED_VERSION, Constants.HeaderConstants.TARGET_STORAGE_VERSION);
        
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_SERVICE, services);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_RESOURCE_TYPE, resourceTypes);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_PERMISSIONS, permissions);

        final String startString = Utility.getUTCTimeOrEmpty(startTime);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_START, startString);

        final String stopString = Utility.getUTCTimeOrEmpty(expiryTime);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_EXPIRY, stopString);

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_RESOURCE, resourceTypes);
        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNED_IP, ipRange != null ? ipRange.toString() : null);
        addIfNotNullOrEmpty(
                builder, Constants.QueryConstants.SIGNED_PROTOCOLS, protocols != null ? protocols.toString() : null);

        addIfNotNullOrEmpty(builder, Constants.QueryConstants.SIGNATURE, signature);

        return builder;
    }
Get the signature hash embedded inside the Shared Access Signature for a {@link CloudStorageAccount}.

@param policy
The shared access policy to hash.
@param ipRange
An optional range of IP addresses.
@param protocols
An optional restriction of allowed protocols.
@param signature
The signature to use.

@return The finished query builder
@throws InvalidKeyException
@throws StorageException