package amazon.webservices.common;
import java.security.SignatureException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
/**
* This class defines common routines for generating
* authentication signatures for AWS requests.
*/
public class Signature {
private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
/**
* Computes RFC 2104-compliant HMAC signature.
* * @param data
* The data to be signed.
* @param key
* The signing key.
* @return
* The Base64-encoded RFC 2104-compliant HMAC signature.
* @throws
* java.security.SignatureException when signature generation fails
*/
public static String calculateRFC2104HMAC(String data, String key)
throws java.security.SignatureException
{
String result;
try {
// get an hmac_sha1 key from the raw key bytes
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
// get an hmac_sha1 Mac instance and initialize with the signing key
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(signingKey);
// compute the hmac on input data bytes
byte[] rawHmac = mac.doFinal(data.getBytes());
// base64-encode the hmac
result = Encoding.EncodeBase64(rawHmac);
} catch (Exception e) {
throw new SignatureException("Failed to generate HMAC : " + e.getMessage());
}
return result;
}
}
分享到:
相关推荐
HMAC-SHA1是一种安全的基于加密hash函数和共享密钥的消息认证协议。
收集了一些RFC2104和hmac-sha1实现的资料,欢迎童鞋们一起学习。
C语言版的实现HMAC-SHA1和base64编码,已经对C++做了兼容处理,在VS下运行main.c代码,可以得到经过HMAC-SHA1处理后的结果,并且可以运行里面的base64编码函数得到想要的结果,可以用于连接阿里云MQTT
对数据进行HMAC-SHA256或HMAC-SHA1加密的C代码,VC2008工程。加密代码来自网络,进行了适当整合。
HMAC是哈希运算消息认证码 (Hash-based Message Authentication Code),HMAC运算利用哈希算法,以一个密钥和一个消息为输入,生成一个消息...HMAC-SHA1签名算法是一种常用的签名算法,用于对一段信息进行生成签名摘要。
hmac-sha1.js文件下载。通过js给对应字段进行hmac的sha1加密解密的操作。
HMAC-SHA1/SHA256/MD5标准dll,参数和返回值全是string型,完美支持其他语言调用,亲测OK,增加了声明类型
HMAC-SHA1 含密钥的安全哈希算法。为了更安全健壮,采用了密钥的安全哈希算法。
目前很多应用的SDK都开始需要Authorization(鉴权),然网络浩瀚,杂乱无章。终于找到了可用的方案,已为腾讯官方做了一个C#的SDK,大家放心copy。
HMAC-SHA256 implementation
把HMAC-SHA1封装为DLL ,此库免费使用。
腾讯云·短信·TC3-HMAC-SHA256API3.0签名V3算法带发送例子
SHA256 和 HMAC-SHA256 的C语言实现,只有一个文件,无库依赖。使用方法见源码底部注释说明
hmac-sha256.js 资源文件,jwt时用到
sha1 mac算法实现
Hmac-SHA1的C C++代码,包含了HMAC-SHA1的算法和参考代码 文件列表:base64.h base64.c HMACSHA.c sha1.c sha1.h
HMAC-SHA1签名demo,已完成测试
强悍,简单明了的HMAC-SHA-1生成加密的消息摘要算法。需要Key作为参数,生成摘要的长度大小可调。经过测试。
Hmac-sha1算法demo,可直接使用。 如有错误,欢迎拍砖