/** * Computes a signature for the specified string using the HMAC-SHA256 algorithm. * * @param value * The UTF-8-encoded string to sign. * * @return A <code>String</code> that contains the HMAC-SHA256-encoded signature. * * @throws InvalidKeyException * If the key is not a valid Base64-encoded string. */ public static synchronized String computeHmac256(final StorageCredentials creds, final String value) throws InvalidKeyException { if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) { byte[] utf8Bytes = null; try { utf8Bytes = value.getBytes(Constants.UTF8_CHARSET); } catch (final UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } return Base64.encode(((StorageCredentialsAccountAndKey) creds).getHmac256().doFinal(utf8Bytes)); } else { return null; } }
/** * Computes a signature for the specified string using the HMAC-SHA256 algorithm. * * @param value * The UTF-8-encoded string to sign. * * @return A <code>String</code> that contains the HMAC-SHA256-encoded signature. * * @throws InvalidKeyException * If the key is not a valid Base64-encoded string. */ public static synchronized String computeHmac256(final StorageCredentials creds, final String value) throws InvalidKeyException { if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) { byte[] utf8Bytes = null; try { utf8Bytes = value.getBytes(Constants.UTF8_CHARSET); } catch (final UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } return Base64.encode(((StorageCredentialsAccountAndKey) creds).getHmac256().doFinal(utf8Bytes)); } else { return null; } }