hmac

Difference between HMACSHA256 and HMACSHA512

ぃ、小莉子 提交于 2019-12-05 17:44:17
问题 We are using the below code to generate a HMac hash against a sensitive value in C# public string GenerateHMac(string key, string message) { var decodedKey = Convert.FromBase64String(key); var hasher = new HMACSHA256(decodedKey); var messageBytes = Encoding.Default.GetBytes(message); var hash = hasher.ComputeHash(messageBytes); return Convert.ToBase64String(hash); } The key passed in is a 256 bit base 64 encoded string. A question was raised as to whether we should be using HMACSHA256,

HMACSHA1.ComputeHash() thread-safety question

有些话、适合烂在心里 提交于 2019-12-05 16:31:54
i am asking myself if it would be dangerous on a asp.net page´s codebehind to use an static (Shared) variable which holds an HMACSHA1-instance. the problem is that the same HMACSHA1-instance would be used by all the asp.net worker-process´ threads when processing multiple simultaneous requests on the same asp.net-page. all (HMACSHA1)instance- and ComputeHash()-method variables which are used/modified by ComputeHash() would be shared (= could be modified) by all the threads?! is that assumption correct? as a result the return value of ComputeHash would not be guaranteed to be correct?!?! thus i

SHA3 status and PBKDF2-HMAC-SHA3 test vectors

血红的双手。 提交于 2019-12-05 16:16:48
Since SHA-3 seems to be an already known function (Keccak as the finalist of NIST hash function competition) I have several questions related to this topic: NIST site says that NIST is closed due to a lapse in government funding. Is there any chance that SHA-3 will ever be finally accepted? BouncyCastle library has an implementation of SHA-3 which digest results are the same as examples posted in wikipedia article (I tested this). Since the final standard is not approved, can this be trusted? Wikipedia says this is likely to be changed but how can it change as the final algorithm does not seem

How to securely verify an HMAC in Python 2.7?

限于喜欢 提交于 2019-12-05 14:50:51
I'm using Python 2.7 and am creating an HMAC using the hmac library. Python 3.3 includes a compare_digest() function that will compare two digests and resist timing attacks, but that's not available in 2.7. Prevailing advice is not to roll my own crypto, so are there any mature Python libraries that provide that functionality? PyCrypto does not appear to. For anyone finding this from search, if using Django, then you can also use the constant_time_compare function in django.utils.crypto . >>> from django.utils.crypto import constant_time_compare >>> constant_time_compare("foo", "bar") False >>

How can I replicate this C# hashing in PHP? (toByteArray(), ComputeHash())

£可爱£侵袭症+ 提交于 2019-12-05 12:56:54
I am trying to replicate the following code in PHP , It is example code for an API I have to interface with (The API & Example code is in C# , My app is in PHP 5.3 ). I'm not a C# developer and so am having trouble doing this. // C# Code I am trying to replicate in PHP var apiTokenId = 1887; var apiToken = "E1024763-1234-5678-91E0-T32E4E7EB316"; // Used to authenticate our request by the API (which is in C#) var stringToSign = string.Empty; stringToSign += "POST"+"UserAgent"+"http://api.com/post"; // Here is the issue, How can I do the following 3 lines in PHP? // No "secret key" provided?..

HMC SHA1 hash - C# producing different hash output than Ruby

强颜欢笑 提交于 2019-12-05 08:51:19
I'm trying to quickly get a buggy .Net client library for a third party service I'm using to work. The original library (which works) is written in Ruby, but their equivalent library for DotNet produces differing hash output to the Ruby library. The Ruby encryption code is as follows: def self.encrypt_string(input_string) raise Recurly::ConfigurationError.new("Recurly gem not configured") unless Recurly.private_key.present? digest_key = ::Digest::SHA1.digest(Recurly.private_key) sha1_hash = ::OpenSSL::Digest::Digest.new("sha1") ::OpenSSL::HMAC.hexdigest(sha1_hash, digest_key, input_string.to_s

PHP HMAC SHA256 Hashing

大憨熊 提交于 2019-12-05 07:48:42
问题 im trying to recreate a script from Java to PHP Usually in php we do hash_mac('sha256',string,key) But the generated signature in php doesnt match the java one... Here is the java algo: Mac localMac = getValidMac(); localMac.init(new SecretKeySpec(str1.getBytes("UTF-8"), localMac.getAlgorithm())); byte[] arrayOfByte = localMac.doFinal(paramString.getBytes()); BigInteger localBigInteger = new BigInteger(1, arrayOfByte); String str4 = String.format("%0" + (arrayOfByte.length << 1) + "x", new

JWT Token Invalid Signature [duplicate]

跟風遠走 提交于 2019-12-05 07:18:27
This question already has an answer here : PHP JWT Token Invalid Signature (1 answer) Closed 2 years ago . I am using JWT in my application for login authentication process. To generate the token I am using: Jwts.builder().setSubject(username).signWith(SignatureAlgorithm.HS512, MacProvider.generateKey()).compact(); Generated Token: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJlaG91c2VAZGV2ZXJldXgub3JnIn0.5SX-aU-p_RlfC3CZa-YXnQu_YR7RsG2Xfim3LOmlqxjAZrIyZiz0fYZwViHr113ms8TNvngcJcV07U4hK-RBZQ When I decode this token in jwt.io debugger it tells me an invalid Signature. I am not able to find the reason of this

Using HMAC vs EVP functions in OpenSSL

心已入冬 提交于 2019-12-05 06:54:19
This is a very basic question, but what is the difference between EVP and HMAC? EVP is a message digest, but how does that differ from what is generated by HMAC? ... what is the difference between EVP and HMAC EVP_* functions are a high level interface. HMAC_* , AES_* and friends are lower level primitives. You can work with either, but its recommended you work with the EVP_* functions. The HMAC_* routines are software based and don't use hardware. The EVP_* functions will allow you to easily swap in different hashes and the code essentially remains the same. And you will take advantage of

HMC SHA1 hash - Java producing different hash output than C#

牧云@^-^@ 提交于 2019-12-05 00:33:02
问题 This is a follow up to this question, but I'm trying to port C# code to Java instead of Ruby code to C#, as was the case in the related question. I am trying to verify the encrypted signature returned from the Recurly.js api is valid. Unfortunately, Recurly does not have a Java library to assist with the validation, so I must implement the signature validation myself. Per the related question above (this), the following C# code can produce the hash needed to validate the signature returned