hmac

Google-App-Script vs php in encoding base64

孤人 提交于 2019-12-11 14:04:09
问题 This php code decodes the secret key before hashing with SHA 512 $API_SECRET_KEY="W0+m0Dc9GMN9yDVeq3GMDsJ49WasEhQHkNHNuDw3wNg="; $BDAPI_SECRET_KEY=base64_decode($API_SECRET_KEY); $HMAC_SIGN = base64_encode(hash_hmac('sha512',$MESSAGE,$BDAPI_SECRET_KEY,true)); echo $HMAC_SIGN; BfVNi21gY09c8M18cWBRBgo1W9pAlXM99ZVoF7Kz2ETFnIuvXjj8NRvRgn/GaT/m6YJ8efsr5s9EDbIhznAaag== I want to replicate this in google app script var Secret = "W0+m0Dc9GMN9yDVeq3GMDsJ49WasEhQHkNHNuDw3wNg=" var BDSecret= Utilities

Should I use Base64 of HMAC digest or just HMAC hex digest?

混江龙づ霸主 提交于 2019-12-11 12:45:03
问题 Legend I expose an API which requires client to sign requests by sending two headers: Authorization: MyCompany access_key:<signature> Unix-TimeStamp: <unix utc timestamp in seconds> To create a signature part, the client should use a secret key issued by my API service. In Python (Py3k) it could look like: import base64 import hmac from hashlib import sha256 from datetime import datetime UTF8 = 'utf-8' AUTH_HEADER_PREFIX = 'MyCompany' def create_signature(access_key, secret_key, message): new

Hashing a csv file in python with a key

二次信任 提交于 2019-12-11 09:59:34
问题 I have a csv file with 1000+ emailadreses which I want to hash using a SHA256 HMAC and a shared key, encoded to Base64. There was a similiar problem here, but I can't adapt the solution to work for me. I am new to python and I don't know where to change the code in order to make use of the shared key. This is the slightly adapted code from the answer: import csv import hashlib import hmac import base64 IN_PATH = 'test.csv' OUT_PATH = 'test_hashed.csv' ENCODING = 'utf8' HASH_COLUMNS = dict

AWS Signature Version 4 S3 Upload using Node.js

喜夏-厌秋 提交于 2019-12-11 06:47:17
问题 I've been following the AWS example on how to generate a V4 HMAC signature. I've done this successfully in Java but I'm trying to get it to work in Node/JavaScript. When I use my code I generate all the correct intermediary keys in their 1st example below but on the next example when given the test StringToSign the same code that generated the correct intermediary keys fails to generate the supposed correct signature. Correct Intermediary Keys: secretkey = 'wJalrXUtnFEMI/K7MDENG

Ruby HMAC signing issue

有些话、适合烂在心里 提交于 2019-12-11 06:01:11
问题 I got an issue with HMAC. I have to sign a form before sending it to a bank. They only provide an example in PHP in their documentation. I have a hex key to sign my data (e.g. FCEBA61A884A938E7E7FE4F5C68AA7F4A349768EE5957DDFBE99C1D05A09CBACF1FCF0A7084CB2E4CBA95193176C4395DE7F39EA9DBEBEF0907D77192AAE3E8A ). In the PHP exemple, they do this with the key before signing the data: $key =

HMAC-SHA256 with AES-256 in CBC mode

断了今生、忘了曾经 提交于 2019-12-11 03:33:09
问题 I recently came across the following code sample for encrypting a file with AES-256 CBC with a SHA-256 HMAC for authentication and validation: aes_key, hmac_key = self.keys # create a PKCS#7 pad to get us to `len(data) % 16 == 0` pad_length = 16 - len(data) % 16 data = data + (pad_length * chr(pad_length)) # get IV iv = os.urandom(16) # create cipher cipher = AES.new(aes_key, AES.MODE_CBC, iv) data = iv + cipher.encrypt(data) sig = hmac.new(hmac_key, data, hashlib.sha256).digest() # return

Why do I get wrong results for hmac in Python but not Perl?

做~自己de王妃 提交于 2019-12-11 03:23:28
问题 I'm trying to compute hmac using sha-512. The Perl code: use Digest::SHA qw(hmac_sha512_hex); $key = "\x0b"x20; $data = "Hi There"; $hash = hmac_sha512_hex($data, $key); print "$hash\n"; and gives the correct hash of 87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cde daa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854 Python version: import hashlib, hmac print hmac.new("\x0b"*20, "Hi There", hashlib.sha512).hexdigest() which gives the incorrect hash of

Generating signed and encrypted JWT

半腔热情 提交于 2019-12-11 02:11:19
问题 I'm trying to generate a signed and encrypted JWT token using Nimbus JWT. private void generateToken() throws JOSEException, NoSuchAlgorithmException, UnsupportedEncodingException { KeyGenerator keyGen = KeyGenerator.getInstance("AES"); keyGen.init(256); SecretKey secretKey = keyGen.generateKey(); JWSSigner signer = new MACSigner(secretKey); JWTClaimsSet claimsSet = new JWTClaimsSet.Builder().subject("subject").build(); SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256),

SHA256 hash the body and base64 encode in Python Vs TypeScript

為{幸葍}努か 提交于 2019-12-11 02:04:16
问题 My goal is to hash the body in SHA256 and then encode it with base64 . I am converting python code to TypeScript . Based on google search, what I understood that, crypto can be used against hashlib and base64 . Here challenge is, when I use .createHmac then it requires the secret when in python I can directly work with body. Is it another way to achieve python result in typeScript ? NOTE: This is the first time I am seeing python code so please correct me if I am missing something here.

Implementing HMAC-SHA256 for Keybase in Javascript

好久不见. 提交于 2019-12-11 02:00:00
问题 I am working with the keybase.io API - trying to drive it from javascript. Logging in is a two step process. The second step is detailed at https://keybase.io/docs/api/1.0/call/login. I am stuck on the following; The server and the client share this secret, and for the client to successfully log the user in, it must prove knowledge of this secret to the server. To protect against replay attacks, it does not send the secret itself. Rather, it treats pwh as MAC key, and MACs the temporary login