List of usage examples for org.apache.commons.codec.digest HmacUtils hmacSha1
public static byte[] hmacSha1(final String key, final String valueToDigest)
From source file:com.qcloud.sign.PicProcessSign.java
public static String sign(int appId, String secret_id, String secret_key, String bucket, long expired) { //a=[appid]&b=[bucket]&k=[SecretID]&t=[currenTime]&e=[expiredTime] if (empty(secret_id) || empty(secret_key)) { return null; }//w w w.jav a 2 s . c om long now = System.currentTimeMillis() / 1000; String plain_text = String.format("a=%d&b=%s&k=%s&t=%d&e=%d", appId, bucket, secret_id, now, expired); byte[] bin = HmacUtils.hmacSha1(secret_key, plain_text); byte[] all = new byte[bin.length + plain_text.getBytes().length]; System.arraycopy(bin, 0, all, 0, bin.length); System.arraycopy(plain_text.getBytes(), 0, all, bin.length, plain_text.getBytes().length); all = Base64.encodeBase64(all); return new String(all); }
From source file:com.lankr.tv_cloud.support.qcloud.image.PicProcessSign.java
public static String sign(int appId, String secret_id, String secret_key, String bucket, long expired, String url) {/*www .j a va 2s . c o m*/ //a=[appid]&b=[bucket]&k=[SecretID]&t=[currenTime]&e=[expiredTime]&l=[url link] if (empty(secret_id) || empty(secret_key)) { return null; } long now = System.currentTimeMillis() / 1000; String plain_text = String.format("a=%d&b=%s&k=%s&t=%d&e=%d&l=%s", appId, bucket, secret_id, now, expired, url); byte[] bin = HmacUtils.hmacSha1(secret_key, plain_text); byte[] all = new byte[bin.length + plain_text.getBytes().length]; System.arraycopy(bin, 0, all, 0, bin.length); System.arraycopy(plain_text.getBytes(), 0, all, bin.length, plain_text.getBytes().length); all = Base64.encodeBase64(all); return new String(all); }
From source file:com.vmware.o11n.plugin.crypto.service.CryptoDigestService.java
/** * HmacSHA1//from w w w . j a v a2 s .c om * * @param keyB64 Secret key Base64 encoded * @param dataB64 Data to sign Base64 encoded * @return HmacSha1 MAC for the given key and data Base64 encoded */ public String hmacSha1(String keyB64, String dataB64) { validateB64(keyB64); validateB64(dataB64); final byte[] key = Base64.decodeBase64(keyB64); final byte[] data = Base64.decodeBase64(dataB64); return Base64.encodeBase64String(HmacUtils.hmacSha1(key, data)); }
From source file:br.com.autonomiccs.apacheCloudStack.client.ApacheCloudStackClient.java
/** * Creates a signature (HMAC-sha1) with the {@link #ApacheCloudStackUser#getSecretKey()} and the given queryString * The returner signature is encoded in Base64. *///from w w w.j a v a2 s .c o m protected String createSignature(String queryString) { byte[] signatureBytes = HmacUtils.hmacSha1(apacheCloudStackUser.getSecretKey(), queryString.toLowerCase()); return Base64.encodeBase64String(signatureBytes); }