I'm trying to create a signature for a privately stored file in Google Cloud Storage; so that I can distribute a time-limited link.
Currently doing this and it makes a signature that's too short ... where am I going wrong?
var crypto = require("crypto");var ttl = new Date().getTime() + 3600;var id = 'the_target_file.txt';var bucketName = 'bucket_name';var POLICY_JSON = "GET\n" + "\n" + "\n" + ttl + "\n" + '/' + bucketName + '/' + id;// stringify and encode the policyvar stringPolicy = JSON.stringify(POLICY_JSON);var base64Policy = Buffer(stringPolicy, "utf-8").toString("base64");// sign the base64 encoded policyvar privateKey = "MY_PRIVATE_KEY";var sha256 = crypto.createHmac("sha256", privateKey);var signature = sha256.update(new Buffer(base64Policy, "utf-8")).digest("base64");console.log ( signature );
Hello Im trying to implement SHA 1 using C++ - just for fun and for understanding HASH functions better. I am following a pseudo code I found in https://en.wikipedia.org/wiki/SHA-1. I am at the main loop where I have to calculate 'temp'. But when I add binary values I am getting numbers larger than 32 bits. There is nothing wrong with my code but is this supposed to happen?
For example: When I add11101000101001000110000000101100and01100111010001010010001100000001I get:01001111111010011000001100101101but technically it should be:0101001111111010011000001100101101
which is larger than 32 bits. Is this supposed to happen or should I just ignore the bits beyond 32? Or am I doing this completely wrong and stick with HEX like the pseudo code?
Any help will be appreciated!
I've been given this Swift code to try and make work in PHP:
finalStr = Encryption.sha256(inputStr)... class Encryption { static func sha256(_ data: Data) -> Data? { guard let res = NSMutableData(length: Int(CC_SHA256_DIGEST_LENGTH)) else { return nil } CC_SHA256((data as NSData).bytes, CC_LONG(data.count), res.mutableBytes.assumingMemoryBound(to: UInt8.self)) return res as Data } static func sha256(_ str: String) -> String? { guard let data = str.data(using: String.Encoding.utf8), let shaData = Encryption.sha256(data) else { return nil } let rc = shaData.base64EncodedString(options: []) return rc } }
I'm doing the following in PHP, but the end result isn't matching:
$hashedStr = hash('sha256', $inputStr);$finalStr = base64_encode($hashedStr);echo $finalStr;
What am I missing on the PHP side?
Here is an algorithm in Java:
public String getHash(String password, String salt) throws Exception { String input = password + salt; MessageDigest md = MessageDigest.getInstance(SHA-512); byte[] out = md.digest(input.getBytes()); return HexEncoder.toHex(out);}
Assume the salt is known. I want to know the time to brute force for when the password is a dictionary word and also when it is not a dictionary word.
I have installed OpenSSL-1.1.1-pre5 and tried to run sha-3 algorithm but i get undefined references EVP_sha3_224 when i run the following c code
#define MSG_SIZE 190#include <stdio.h>#include <string.h>#include <openssl/evp.h>void str2hex(char *str, unsigned char *hex, int len) { int tt, ss; char temp[5]; for (tt = 0, ss = 0; tt < len, ss < 2 * len; tt++, ss += 2) { temp[0] = '0'; temp[1] = 'x'; temp[2] = str[ss]; temp[3] = str[ss + 1]; temp[4] = 0; hex[tt] = strtol(temp, NULL, 0); }}int main(){unsigned char stringt[MSG_SIZE],digest[MSG_SIZE];size_t len;unsigned char buffer[32];const EVP_MD *md;char *string = "45927e32ddf801caf35e18e7b5078b7f5435278212ec6bb99df884f49b327c6486feae46ba187dc1cc9145121e1492e6b06e9007394dc33b7748f86ac3207cfe";md = EVP_sha3_224();str2hex(string, stringt, MSG_SIZE);EVP_MD_CTX *hashctx;hashctx = EVP_CIPHER_CTX_new();EVP_DigestInit_ex(hashctx, md, NULL);EVP_DigestUpdate(hashctx, stringt, strlen(string)/2);unsigned int outlen;EVP_DigestFinal_ex(hashctx, digest, &outlen);EVP_MD_CTX_cleanup(hashctx);int i;for (i = 0; i < outlen; i++) printf("%02x", digest[i]);}
Can someone help me figure out what might be the reason. for this error.
Dom - Mapa strony - Prywatność - Odnośniki - Copyright © 2018 Cortex IT Ltd : Kontakt : admin @ cortexit.co.uk
Please note that by viewing our site you agree to our use of cookies (see Prywatność for details). You will only see this message once.