Tag: hmac

如何在C#中生成HMAC-SHA1?

我正在尝试使用C#使用REST API。 API创build者已经提供了PHP,Ruby和Java的示例库。 我正在挂上它的一部分,我需要生成一个HMAC 。 以下是他们提供的示例库中的工作方式。 PHP hash_hmac('sha1', $signatureString, $secretKey, false); ruby digest = OpenSSL::Digest::Digest.new('sha1') return OpenSSL::HMAC.hexdigest(digest, secretKey, signatureString) Java的 SecretKeySpec signingKey = new SecretKeySpec(secretKey.getBytes(), HMAC_SHA1_ALGORITHM); Mac mac = null; mac = Mac.getInstance(HMAC_SHA1_ALGORITHM); mac.init(signingKey); byte[] bytes = mac.doFinal(signatureString.getBytes()); String form = ""; for (int i = 0; i < bytes.length; i++) { String str = […]

HMAC-SHA256签名计算algorithm

我正在尝试使用HMAC-SHA256algorithm创build签名,这是我的代码。 我正在使用美国ASCII编码。 final Charset asciiCs = Charset.forName("US-ASCII"); final Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); final SecretKeySpec secret_key = new javax.crypto.spec.SecretKeySpec(asciiCs.encode("key").array(), "HmacSHA256"); final byte[] mac_data = sha256_HMAC.doFinal(asciiCs.encode("The quick brown fox jumps over the lazy dog").array()); String result = ""; for (final byte element : mac_data) { result += Integer.toString((element & 0xff) + 0x100, 16).substring(1); } System.out.println("Result:[" + result […]

HMAC vs简单的MD5哈希

任何人都可以指出使用HMАC的优点是什么? 例如,如果我有文本T和密钥K ,则可以使用HMAC-MD5algorithm或Md5(T + K)来获得签名。

如何用Java生成等价于Python示例的HMAC?

我正在考虑通过 Java中的Oauth实现一个获得Twitter授权的应用程序。 第一步是获取请求令牌 。 以下是应用程序引擎的Python示例 。 为了testing我的代码,我正在运行Python并使用Java检查输出。 以下是生成基于哈希的消息authentication码(HMAC)的Python示例: #!/usr/bin/python from hashlib import sha1 from hmac import new as hmac key = "qnscAdgRlkIhAUPY44oiexBKtQbGY0orf7OV1I50" message = "foo" print "%s" % hmac(key, message, sha1).digest().encode('base64')[:-1] 输出: $ ./foo.py +3h2gpjf4xcynjCGU5lbdMBwGOc= 如何在Java中复制这个例子? 我在Java中看到了一个HMAC的例子 : try { // Generate a key for the HMAC-MD5 keyed-hashing algorithm; see RFC 2104 // In practice, […]

Message Digest,Message Authentication Code和HMAC有什么区别?

我对消息摘要的理解是,它是与encryption数据一起发送的一些数据的encryption散列,因此您可以validation数据没有被篡改。 这个和消息authentication码(MAC)和散列MAC(HMAC)之间有什么区别?

如何在没有HTTPS的情况下使用JavaScript通过HTTP安全地发送密码?

所有开发人员都面临的基本问题是:无论何时用户提交表单,密码都是通过networking发送的,并且必须受到保护。 我开发的网站没有HTTPS。 所有者也不想购买SSL证书,也不想购买自己的SSL证书。 所以我想在提交表单时保护通过HTTP使用JavaScript发送的密码。 渴望downvoters: 如何通过HTTP安全地发送密码? 没有给出任何明智的解决办法,我处于另一种情况。 如果我使用MD5,则可以反转该密码string。 那么nonce / HMAC呢? 任何可用的Javascript库? 或者你有什么build议/暗示来解决? 提前致谢!

HMAC-SHA1:如何在Java中正确执行?

我使用HMAC-SHA1散列一些值,在Java中使用以下代码: public static String hmacSha1(String value, String key) { try { // Get an hmac_sha1 key from the raw key bytes byte[] keyBytes = key.getBytes(); SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1"); // Get an hmac_sha1 Mac instance and initialize with the signing key Mac mac = Mac.getInstance("HmacSHA1"); mac.init(signingKey); // Compute the hmac on input data […]

HMAC-SHA1在bash中

是否有一个生成HMAC-SHA1哈希的bash脚本? 我正在寻找相当于以下PHP代码的东西: hash_hmac("sha1", "value", "key");

在Python中实现HMAC-SHA1

我试图使用一个网站的OAuth,这需要签名方法是“HMAC-SHA1”。 我想知道如何在Python中实现这个?

java相当于php的hmac-SHA1

我在找一个相当于这个php调用的java: hash_hmac('sha1', "test", "secret") 我试过这个,用java.crypto.Mac ,但是两者不同意: String mykey = "secret"; String test = "test"; try { Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec secret = new SecretKeySpec(mykey.getBytes(),"HmacSHA1"); mac.init(secret); byte[] digest = mac.doFinal(test.getBytes()); String enc = new String(digest); System.out.println(enc); } catch (Exception e) { System.out.println(e.getMessage()); } key =“secret”和test =“test”的输出似乎不匹配。